Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created April 9, 2010 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepijndevos/361212 to your computer and use it in GitHub Desktop.
Save pepijndevos/361212 to your computer and use it in GitHub Desktop.
import pythoncom, pyHook
from time import sleep
from pymouse import PyMouseMeta, PyMouseEventMeta
class PyMouseEvent(PyMouseEventMeta):
def __init__(self):
PyMouseEventMeta.__init__(self)
self.listen = True
self.start()
def run(self):
hm = pyHook.HookManager()
# watch for all mouse button events
hm.MouseAllButtons = self._click
# watch for mouse move events
hm.MouseMove = self._move
# set the hook
hm.HookMouse()
# wait for events
while self.listen:
try:
sleep(0.01)
finally:
pythoncom.PumpWaitingMessages()
#hm.UnhookMouse()
del hm
def _click(self, event):
x,y = event.Position
state = (
int(int(event.Message==pyHook.HookConstants.WM_LBUTTONDOWN)),
int(int(event.Message==pyHook.HookConstants.WM_MBUTTONDOWN)),
int(int(event.Message==pyHook.HookConstants.WM_RBUTTONDOWN))
)
#print x,y,state
self.click(x,y,state)
return True
def _move(self, event):
x,y = event.Position
#print x,y
self.move(x,y)
return True
def __del__(self):
self.listen = False
self.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment