Recently I have shown how to launch MagicMirror from RetroPie. You can check it out here! Now I want to show the opposite: How to access RetroPie from MagicMirror (running on LXDE desktop) using USB joystick buttons (by replacing mouse and keyboard). It’s possible to quit MagicMirror and to end LXDE desktop and go back to RetroPie by creating custom keyboard shortcuts and mapping them to the joystick buttons.
You have to modify lxde-pi-rc.xml, a file that holds shortcuts settings, saved in /etc/xdg/openbox/. I recommend to create a folder called openbox at /home/pi/.config/ and save a copy there. This way the configuration file will run locally instead of globally and you can modify it completely. You can go back to the original configuration by deleting the local file so the untouched global file can be used.
$ cd /home/pi/.config $ mkdir openbox $ cd openbox $ cp /etc/xdg/openbox/lxde-pi-rc.xml $ nano lxde-pi-rc.xml
Now you can edit the file. First you search for keybindings for running applications (you can get there by typing CTRL+W and writing “Keybindings”), then you can add code for other shortcuts. At the example I added a shortcut for CTRL+A (key=”C-a”), to execute the mirror.sh script that starts MagicMirror, and for CTRL+C (key=”C-c”), to end LXDE desktop and go back to RetroPie. It’s good to remember that these shortcuts only work on the LXDE desktop. If you are logging into the command prompt via SSH, for example, it will not work.
<!-- Keybindings for running applications --> <keybind key="C-c"> <action name="Execute"> <command>killall xinit</command> </action> </keybind> <keybind key="C-a"> <action name="Execute"> <command>bash /home/pi/Documents/mirror.sh</command> </action> </keybind>
You can write mirror.sh code saved in /home/pi/Documents as described bellow.
#!/bin/bash cd /home/pi/MagicMirror DISPLAY=:0 npm start
Don’t forget to make mirror.sh executable by tipping the following code at command line.
$ sudo chmod +x /home/pi/Documents/mirror.sh
To use your USB joystick as a keyboard you have to install the joystick input driver and the joystick configuration package. To test and calibrate the gamepad you can run jstest-gtk.
$ sudo apt-get install joystick $ sudo apt-get install jstest-gtk $ jstest-gtk
The next step is to install QJoyPad. This way you can map some keys of the keyboard to your joystick buttons.
$ sudo apt-get install qjoypad
Note that I saved my settings as Arcade and I mapped the keys CTRL, Q, A and C. So now I can use my joystick to start MagicMirror (CTRL+A), to quit an application (CTRL+Q) and to quit the desktop and go back to RetroPie (CTRL+C). You can map other keys to run any application that you want.
Now you have to guarantee that QJoyPad is executed automatically as soon as the desktop starts. First you have to create a file to call this application. Let’s call the file qpad.desktop and save it in /home/pi/.config/autostart to run at every boot. You’ll have to create the autostart folder if it doesn’t exist.
$ cd /home/pi/.config/ $ mkdir autostart $ cd autostart $ nano qpad.desktop
Save the code bellow as qpad.desktop. Note the last code line that you have to pass your saved settings as parameter (Arcade).
[Desktop Entry] Type=Application Name=qpad Exec=qjoypad "Arcade"
Finally you can go back to RetroPie from MagicMirror!! If you want to do the same thing but using instead a push button connected to a GPIO pin from the Raspberry Pi, click here! This way you can also disable the USB ports to save energy.
I hope you enjoyed and learned something new! See you around!! 🙂