How can I use a button on my bluetooth gamepad to execute a shell script on my rpi 3 in raspbian?


Ahh yes, I may be able to help you.

When I installed RetroPie I was working on keymapping a Wii remote. Wii remotes are Bluetooth, so I linked my Pi to my remote. I failed to keymap the entire thing except for the D-Pad (directional pad). The D-pad were acting as the up, down, left, and right arrows of the keyboard.

If you made another script listening for the key press of a key like that, it could react, and activate the script. Except with your Gamepad it could be different.

Try pairing them and try the key presses in a keymapping tool.

Hope this helps, Dallin

  • I found xbindkeys to map the command to a key, but I cannot find the keycode for the button. I used evtest to test the button, and the one I want to use is called "event code 304 (BTN_SOUTH)" but I've tried every possible combination of that in the xbindkeys config and nothing happens. XEV and xbindkeys -k show nothing when I press the gamepads buttons. – axxic3 Oct 19 '16 at 5:41
  • I don't know keymapping. I used the built in keymapper and it just said that the up arrow was up on the keyboard. – Dallin Wright Oct 20 '16 at 2:57

I used xbindkeys_config which is a seperate package than just the standard xbindkeys. It uses a gui instead of configuring a text file. Also my bluetooth controller had a switch on the back to change from gamepad mode to keyboard mode, which I originally had on gamepad. When switched to keyboard the xbindkeys config easily recognized the buttons and gave me no problems. In the gui I also set the command to run a shell script which was very easy as well. So if your having issues with your keycodes give xbindkeys a try. Thanks for pointing me in the right direction Dallin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.