使用pyHook获取鼠标坐标以便稍后播放 [英] Using pyHook to get mouse coordinates to play back later

查看:227
本文介绍了使用pyHook获取鼠标坐标以便稍后播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一大堆代码,以使用pyHook收集鼠标单击信息,然后使用win32api以获得对单击功能的访问.本质上,我试图使用鼠标来记录要记录的点击模式,以便以后记录和播放.

I am writing a chunk of code to get gather mouse click information using pyHook and then the win32api to get access to a click function. Essentially I am trying to use the mouse to record a pattern of clicks to be recorded and played back later.

这是我目前的代码:

import win32api, win32con, time, win32ui, pyHook, pythoncom

#Define the clicks in the win32api
def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

def onclick(event):
    click()
    print event.Position
    return True

hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(click)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()

我确定有些简单的事情很愚蠢.

I am sure there is something stupidly simple.

这也是我从运行此命令得到的调试:

Also here is the debug I got from running this:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pyHook\HookManager.py", line 325, in MouseSwitch
return func(event)
TypeError: click() takes exactly 2 arguments (1 given)

推荐答案

hm.SubscribeMouseAllButtonsDown(click)-> hm.SubscribeMouseAllButtonsDown(onclick)

已删除onclick中的click()呼叫.

import win32api, win32con, time, win32ui, pyHook, pythoncom

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

def onclick(event):
    print event.Position
    return True

hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()

这篇关于使用pyHook获取鼠标坐标以便稍后播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆