Python win32api.mouse\u事件类型E

2024-04-29 13:59:39 发布

您现在位置:Python中文网/ 问答频道 /正文

import sys
import win32api, win32con
import pyHook
import pythoncom

def CursorLeft():
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, -1, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)

def Quit():
    print "Quitting"
    sys.exit()

# create a keyboard hook
def OnKeyboardEvent(event):
    print 'MessageName:', event.MessageName
    print 'Key:', event.Key
    if event.Key in ['Numpad2']:
        CursorLeft()
    elif event.Key in ['End']:
        Quit()
    return True

def OnMouseEvent(event):
    print 'Position:', event.Position
    return True

hm = pyHook.HookManager()
hm.MouseAll = OnMouseEvent
hm.HookMouse()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

CursorLeft函数每隔一段时间运行良好。它在没有任何负数作为参数的情况下也能正常工作。我完全不明白为什么会发生这种事!在

第一个电话,好的。在

第二个电话

TypeError: an integer is required

第三个电话,好的。在

第四次通话

TypeError: an integer is required.

等等等等。在






<罢工>

已解决

^{pr2}$

传递的最后两个参数允许函数正常运行。我还不知道为什么,我想知道这是为什么,但至少现在它正在工作。 在

已解决

return True

事件函数返回true非常重要。在


Tags: key函数importeventtruereturndef电话