How can i memorize when i press a JoyButtons?

Hi, I’m trying to create an experiment in PsychoPy (v2023.1.3).
I would need to memorize when I start pressing a JoyButtons button and when I finish pressing it.
For now I’ve only managed to store when I start pressing the button but not when it’s released, by setting the JoyButtons with Properties>Data>Store: all keys.
Do any of you know how to add or find this feature? Thanks so much.


In PsychoPy Builder, use the JoyButtons component to track joystick button presses. Modify its settings to store specific data. To record button release, add code to monitor the button’s state. You can use the following code in a code component to achieve this:

# Begin Routine
thisResp = []
joy = joystick.Joystick(0)
# End Routine

# Each Frame
keys = joy.get_button(0) # 0 is the button number
if keys:
    if len(thisResp) > 0:
        thisExp.addData('response', ''.join(thisResp))
        thisExp.addData('RT', t)
        continueRoutine = False

This code kick-starts the joystick and checks each frame for button presses. Any presses are logged in a response list. If there’s no button pressed and the list isn’t empty, the routine records the response and timing and wraps up. The code’s set for button 0; change the button number for others.

Hope this helps.