I want to create a program that catches mouse clicks, no matter in which application it is sent to. Then it has to simulate twenty mouse clicks in one second. I am quite new to Python, and I am not really understanding much, but I've searched in several sites and I assembled this code:
import time
import ctypes
import pyHook
import pythoncom
MOUSEEVENTF_MOVE = 0x0001 # mouse move
MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move
MOUSEEVENTF_MOVEABS = MOUSEEVENTF_MOVE + MOUSEEVENTF_ABSOLUTE
MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down
MOUSEEVENTF_LEFTUP = 0x0004 # left button up
MOUSEEVENTF_CLICK = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP
def click(vdf):
hm.UnhookMouse()
ctypes.windll.user32.mouse_event(MOUSEEVENTF_CLICK, 0, 0, 0, 0)
time.sleep(1)
ctypes.windll.user32.mouse_event(MOUSEEVENTF_CLICK, 0, 0, 0, 0)
hm.HookMouse()
return 0
hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(click)
hm.HookMouse()
pythoncom.PumpMessages()
os.system("pause")
This is just a sample. It has to generate 2 mouse clicks with a second interval. When I start it however, that's what comes out:
Traceback (most recent call last):
File "C:\Documents and Settings\Valjo\Desktop\hack.py", line 3, in <module>
import pyHook
File "D:\Python2.7\lib\site-packages\pyHook\__init__.py", line 1, in <module>
from HookManager import *
File "D:\Python2.7\lib\site-packages\pyHook\HookManager.py", line 1, in<module>
import cpyHook
File "D:\Python2.7\lib\site-packages\pyHook\cpyHook.py", line 9, in <module>
new_instancemethod = new.instancemethod
AttributeError: 'module' object has no attribute 'instancemethod'
And it creates some file named new.pyc
...
Any ideas how to fix it? Thanks!
Use eventghost: http://www.eventghost.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With