I want to start off by saying that I am new to Python so I am sorry if this question is going to sound stupid to you.
I am just looking for an easy way to trigger a function whenever I press the left click of my mouse. Could anyone illustrate me how to achieve this? Examples are greatly appreciated.
My code now:
import win32api
import win32con
import time
from random import randint
import pythoncom, pyHook
def OnMouseEvent(event): #triggers mouseClick function
mouseClick(event)
return True
def mouseClick(event):
if event.MessageName == "mouse left up": # makes sure that's the event I'm looking for
a = True # disables hm.MouseAll
return a
time.sleep(0.01)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
time.sleep(0.005)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
time.sleep(0.01)
a = False # enables hm.MouseAll back
return a
a = False
# create a hook manager
hm = pyHook.HookManager()
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()
# watch for all mouse events
while True:
if a == False:
hm.MouseAll = OnMouseEvent # Triggers OnMouseEvent function
else:
pass