Created
April 9, 2010 14:25
-
-
Save pepijndevos/361212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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