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!
Axarydax
16.7k23 gold badges95 silver badges157 bronze badges
asked Dec 4, 2010 at 14:37
user530476
1991 gold badge2 silver badges5 bronze badges
1 Answer 1
Use eventghost: http://www.eventghost.org/
- Open source
- You can write plugins in Python
- You can catch lots of different events (you can even capture raw HID devices)
- You can make it run/do anything you could normally do with Python
answered Jan 19, 2011 at 19:47
Wolph
80.4k12 gold badges142 silver badges152 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
user530476
I don't really need this. J.F. Sebastien already helped me to fix my code.
lang-py
new.pyand it shadowsnewmodule from Python's stdlib. Write in your script:import new; print new.__file__. What is the output?