Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need an input control program in python

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!

like image 273
user530476 Avatar asked Dec 04 '10 14:12

user530476


1 Answers

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
like image 53
Wolph Avatar answered Sep 23 '22 12:09

Wolph