该脚本应该在按F9键后开始打印操纵杆轴位置,而在再次按F9键后停止打印,但是我遇到了这个奇怪的错误
line 27, in <module>
clock.tick(20)
TypeError: an integer is required
当我在IDLE中运行它时,它最初可以工作,并且在第三次按F9键后出现错误。
记录变量中那个奇怪的1和-1值是因为当我使用布尔值时,关于该变量我得到了类似的错误。
import pygame
import pythoncom, pyHook
pygame.init()
clock = pygame.time.Clock()
recording = (-1)
def OnKeyboardEvent(event):
if event.KeyID==120: #F9
global recording
recording = recording * (-1)
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
while True:
if recording == 1:
joystick = pygame.joystick.Joystick(0)
joystick.init()
axis0 = joystick.get_axis(0)
print axis0
clock.tick(20)
pythoncom.PumpWaitingMessages()
Python 2.7,Windows XP