加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python win32api.mouse_event TypeError

发布时间:2020-12-20 13:29:40 所属栏目:Python 来源:网络整理
导读:import sysimport win32api,win32conimport pyHookimport pythoncomdef CursorLeft(): win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,-1,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0)
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)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,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.

等等.

解决了

win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,0)

传递的最后两个参数允许函数正常运行.我仍然不确定为什么,仍然想知道,但至少它现在正在工作.

解决了

return True

事件函数返回true非常重要.

解决方法

复制评论中的答案,以便从“未答复”过滤器中删除此问题:

return True

Very important that the event functions return true.

?每Junkah回答一次

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读