1

The script is supposed to start printing the joystick axis position after pressing F9 and stop the printing after another press, but I get this strange error

line 27, in <module>
clock.tick(20)
TypeError: an integer is required

When I run this in IDLE it works initially and an error appears after third F9 key press.

That strange value of 1 and -1 in recording variable is because when I was using boolean I was getting similar errors in respect to that variable.

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

Cubed
  • 102
  • 7
xvel
  • 11
  • 1

0 Answers0