Bonjour
Je cherche a créer un script python qui me permettrait d'effectuer un clic de souris toute les 0.2 secondes lorsque je maintiens appuyé le bouton de cette même souris.
Mes recherches m'ont amené à ce script pour ce qui est de faire cliquer la souris automatiquement :
Je n'ai donc qu'a appeler la fonction l_click pour effectuer un clic gauche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import win32api import win32con from ctypes import windll import time def m_move(x,y): windll.user32.SetCursorPos(x,y) def l_click(x="current", y="current"): if x == "current" and y == "current": win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0) time.sleep(0.05) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0) else: win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y) time.sleep(0.05) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y) def r_click(x="current", y="current"): if x == "current" and y == "current": win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0) time.sleep(0.05) win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0) else: win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, x, y) time.sleep(0.05) win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, x, y)
Le problème c'est que je n'arrive pas à détecter si le bouton gauche de la souris est enfoncé. J'ai trouvé un script utilisant pyhook mais je n'ai pas compris son fonctionnement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 import pyHook import pythoncom def onclick(event): print event.Position return True hm = pyHook.HookManager() hm.SubscribeMouseAllButtonsDown(onclick) hm.HookMouse() pythoncom.PumpMessages() hm.UnhookMouse()
Partager