getBtnPressed is a function to use in Pyxel, which returns a string depending on the key or button pressed, thus avoiding having to use long IF statements to know if, for example, the up arrow key was pressed or that same direction on the d-pad of a controller.
Copy the function anywhere in your game code. Remember to add self as a function parameter if you will include it in a class.
The values returned are:
- Arrow up or press up on the d-pad: 'up'.
- Arrow down or press down on the d-pad: 'down'.
- Left arrow or press left on the d-pad: 'left'
- Right arrow or press right on the d-pad: 'right'
- Z key or A button on the controller: 'a'
- X key or B button on the joystick: 'b'
- Enter key or Start button on the controller: 'start'
- Space key or Select/Back button on the joystick: 'select'
This function has been tested with an Xbox controller and the RS36S controller.