需要一个python输入控制程序
我想创建一个程序来捕获鼠标点击,无论它发送到哪个应用程序。然后它必须在一秒钟内模拟二十次鼠标点击。我对Python很陌生,我不太了解,但我在几个网站上进行了搜索并组装了这段代码:
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")
这只是一个示例。它必须以第二个间隔生成 2 次鼠标单击。然而,当我启动它时,结果如下:
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'
它创建了一些名为 new.pyc
的文件...
有什么解决办法吗? 谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用eventghost: http://www.eventghost.org/
Use eventghost: http://www.eventghost.org/