How to detect that button 0 or button 1 has been pressed with the Joystick component of the API?

Hi everyone,

OS (e.g. Win10): MacOS Mojave
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone? (y/n) : y
What are you trying to achieve?:
Use a joystick/gamepad with 2 buttons to store a value if button 0 is pressed and store another value if button 1 is pressed.**
What did you try to make it work?:
I created a Joystick component and allowed buttons 0 and 1
What specifically went wrong when you tried that?:
I don’t know the methods/functions to check which button has been pressed with the Joystick component of the API.

When I created my joystick directly in python everything worked:
from psychopy.hardware import joystick
joy = joystick.Joystick(0)
bttnPress = joy

but having created my joystick “joystick_lang” through the interface, if I try to put “joystick_lang.getButton(1)”, in a code component, it doesn’t work. The error is: object has no attribute ‘getPressed’.

Psychopy interface:

code_lang component:

Ok so I used dir method to list the methods of the Joystick component: print(dir(joystick_lang))
I found getAllButtons() that list all the different buttons states (true if pressed). It would be nice to add this method to the documentation.
Therefore my if condition to check if the button 1 is pressed is as follow:

if joystick_lang.getAllButtons()[1]: