python怎么识别鼠标的动作_使用python检测窗口中的鼠标点击
在程序外部檢測鼠標事件的唯一方法是使用
SetWindowsHookEx安裝Windows鉤子.
pyHook模塊封裝了細節細節。以下是一個示例,它將打印每次鼠標點擊的位置:
import pyHook
import pythoncom
def onclick(event):
print event.Position
return True
hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
您可以檢查與模塊一起安裝的example.py腳本,以獲取有關event參數的更多信息。
因為pyHook需要一個活動的消息泵,所以pyHook可能會在純Python腳本中使用很棘手。從tutorial:
Any application that wishes to receive notifications of global input events must have a Windows message pump. The easiest way to get one of these is to use the PumpMessages method in the Win32 Extensions package for Python. […] When run, this program just sits idle and waits for Windows events. If you are using a GUI toolkit (e.g. wxPython), this loop is unnecessary since the toolkit provides its own.
總結
以上是生活随笔為你收集整理的python怎么识别鼠标的动作_使用python检测窗口中的鼠标点击的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vscode让html文件保存自动刷新浏
- 下一篇: 思科模拟器Cisco Packet Tr