AT THE MOMENT JOYSTICK DOES NOT APPEAR TO WORK UNDER PYGLET. We need someone motivated and capable to go and get this right (problem is with event polling under pyglet)
Control joysticks and gamepads from within PsychoPy
You do need a window (and you need to be flipping it) for the joystick to be updated.
Typical usage:
from psychopy.hardware import joystick
from psychopy import visual
joystick.backend='pyglet' # must match the Window
win = visual.Window([400,400], winType='pyglet')
nJoys = joystick.getNumJoysticks() # to check if we have any
id = 0
joy = joystick.Joystick(id) # id must be <= nJoys - 1
nAxes = joy.getNumAxes() # for interest
while True: # while presenting stimuli
currentjoy.getX()
# ...
win.flip() # flipping implicitly updates the joystick info
psychopy.hardware.joystick.
getNumJoysticks
()¶Return a count of the number of joysticks available.
psychopy.hardware.joystick.
Joystick
(id)¶An object to control a multi-axis joystick or gamepad
Known issues: | Currently under pyglet backends the axis values initialise to zero rather than reading the current true value. This gets fixed on the first change to each axis. |
---|
getAllAxes
()¶Get a list of all current axis values
getAllButtons
()¶Get the state of all buttons as a list
getAllHats
()¶Get the current values of all available hats as a list of tuples. Each value is a tuple (x, y) where x and y can be -1, 0, +1
getAxis
(axisId)¶Get the value of an axis by an integer id (from 0 to number of axes - 1)
getButton
(buttonId)¶Get the state of a given button.
buttonId should be a value from 0 to the number of buttons-1
getHat
(hatId=0)¶Get the position of a particular hat. The position returned is an (x, y) tuple where x and y can be -1, 0 or +1
getName
()¶Returns the manufacturer-defined name describing the device
getNumAxes
()¶Returns the number of joystick axes found
getNumButtons
()¶Returns the number of digital buttons on the device
getNumHats
()¶Get the number of hats on this joystick
getX
()¶Returns the value on the X axis (equivalent to joystick.getAxis(0))
getY
()¶Returns the value on the Y axis (equivalent to joystick.getAxis(1))
getZ
()¶Returns the value on the Z axis (equivalent to joystick.getAxis(2))