需要一个python输入控制程序

发布于 2024-10-06 04:47:13 字数 1544 浏览 4 评论 0原文

我想创建一个程序来捕获鼠标点击,无论它发送到哪个应用程序。然后它必须在一秒钟内模拟二十次鼠标点击。我对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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-10-13 04:47:13

使用eventghost: http://www.eventghost.org/

  • 开源
  • 你可以用Python写插件
  • 你可以catch许多不同的事件(您甚至可以捕获原始 HID 设备)
  • 您可以让它运行/执行您通常可以使用 Python 执行的任何操作

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文