0

所以我一直在研究一个非常基本的“fastclick 宏”。如果我的点击速度超过每秒 5 次点击,我希望程序点击更多。当它达到每秒 5 次点击的限制时,我希望它在您的最后一次点击和下一次点击之间点击,使用time.sleep(clicktime / 2). 出于某种原因,我收到一个错误:

需要一个整数(获取类型 NoneType)

这是我的代码:

import pythoncom, pyHook, sys, winsound, os
import win32api, win32con, random, time
from pyHook import HookManager
from pyHook.HookManager import HookConstants

macro = False
tip = 1
firstclick = 0
secondclick = 0
clicktime = 1

bot = False

def ExtraClick():
    global clicktime
    global bot
    x, y = win32api.GetCursorPos()
    print('click')
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0) 
    bot = True  

def OnMouseClick(event):
    global tip
    global firstclick
    global secondclick
    global clicktime
    global macro
    global bot

    if bot == True:
        bot = False

    if bot == False:
        if tip == 0:
            tip = 1
            firstclick = time.time()
            clicktime = firstclick - secondclick
            print(clicktime)


        elif tip == 1:
            tip = 0
            secondclick = time.time()
            clicktime = secondclick - firstclick
            print(clicktime)                    


def OnKeyEvent(event):
    global macro
    if event.KeyID == 192:
        if macro == True:
            macro = False
            print('off')
            winsound.Beep(600, 30)
            winsound.Beep(550, 30)
        else:
            macro = True
            print('on')
            winsound.Beep(1000, 30)
            winsound.Beep(1100, 30)
            clickspeed = 1

hm = pyHook.HookManager()
while True:
    hm.MouseLeftDown = OnMouseClick
    hm.KeyDown = OnKeyEvent    
    if clicktime < 0.20 and macro == True:
        time.sleep(clicktime / 2)
        ExtraClick()      
    hm.HookMouse()
    hm.HookKeyboard()
    pythoncom.PumpWaitingMessages()

我也尝试过,而不是使用time.sleep(clicktime / 2), time.sleep(0.1),但这给出了同样的错误。

4

1 回答 1

0

问题不在于 time.sleep 而在于 pyhook - 似乎它要求处理程序返回一个值(True 或 False)。

看到这个答案:帮助 pyHook 错误

添加return True到事件处理程序的末尾。

于 2016-03-05T12:04:21.403 回答