time.sleep(得到类型 NoneType)
time.sleep (got type NoneType)
所以我一直在研究一个非常基础的 'fastclick macro'。如果我的点击速度超过每秒 5 次左右,我希望程序点击更多。当它达到每秒 5 次点击的限制时,我希望它在你的最后一次点击和你的下一次点击之间点击,用 time.sleep(clicktime / 2)
完成。出于某种原因,我得到一个错误:
an integer is required (got type 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)
,但是这给出了同样的错误。
问题不在于 time.sleep,而在于 pyhook - 它似乎需要处理程序 return 一个值(真或假)。
看到这个答案:Help with pyHook error
将 return True
添加到事件处理程序的末尾。
所以我一直在研究一个非常基础的 'fastclick macro'。如果我的点击速度超过每秒 5 次左右,我希望程序点击更多。当它达到每秒 5 次点击的限制时,我希望它在你的最后一次点击和你的下一次点击之间点击,用 time.sleep(clicktime / 2)
完成。出于某种原因,我得到一个错误:
an integer is required (got type 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)
,但是这给出了同样的错误。
问题不在于 time.sleep,而在于 pyhook - 它似乎需要处理程序 return 一个值(真或假)。
看到这个答案:Help with pyHook error
将 return True
添加到事件处理程序的末尾。