On Retroarch, there are 'system' commands; they allow you to display the menu, pause, reset the ROM, load/save the game state...
However, there is a limitation to using these commands, but let's first see how they work before showing how to enhance their usage: assign a key for loading and another for saving!
Two possibilities are offered to customize the trigger for these functions:
The first method, with a configured Hotkey, is the default on Retroarch and is probably the most used because it offers many practical features by reusing existing keys for game commands (if there are 8 function keys and a stick, this allows for 11 commands). However, it has the disadvantage of a lack of speed.
Certainly, if you just want to exit the current game, pressing 2 keys at the same time is not a timing issue in itself. However, if you want to save a game quickly at a moment when time is crucial, locating and pressing 2 keys simultaneously takes a time lapse that can be critical depending on the game. And there is a risk of error (for example, you might confuse saving with loading).
The second method (no Hotkey) no longer has the disadvantage of the critical time lapse for saving but requires having as many keys available as there are functions to use: you need one key to exit the game, another to access Retroarch settings, another to load, another to save, and two more to navigate through the saves... In short, a whole keyboard!
Ideal would have been to configure Retroarch to indicate that a certain system function is called either by a dedicated key or by a Hotkey+key combination.
By looking through the Retroarch documentation, we learn that it listens to certain ports, notably port 55355, to allow executing commands over the network: exit, take screenshots, adjust volume... This is indicated here.
In the Batocera documentation (which launches Retroarch), we learn that we can create a key configuration file to launch scripts. This documentation suggests adjusting the brightness or volume of Batocera when certain keys are pressed.
You understand the idea: when pressing a specific key, the goal is to send a local network command that will be processed by Retroarch. The Hotkey remains in use, but direct calls to certain keys are intercepted to send commands to Retroarch.
The ideal is to have one key to save the state of a game and another key to load that state.
First, you will need to find the technical name of these 2 keys. One method to achieve this is to connect via SSH to your machine and launch the evtest software.
This will display, when you press a key, the status and name of that key. In my case, I get this for the 'save' key:
type : 1 (EV_KEY), code 296 (BTN_BASE3), value 1 => 0
And that for the 'Load' touch:
type : 1 (EV_KEY), code 297 (BTN_BASE4), value 1 => 0
I wrote a script in two differents languages (Python and Bash). Both work in my case, but I have a preference for the Bash script as it is probably faster. I will provide both here, to choose according to individual preferences...
The different outputs (echo and print) will obviously not be displayed and are only for debugging purposes.
Both scripts check if Retroarch is running. If it is, they will initiate the loading or saving of the game state. If it is not, they will change the brightness on EmulationStation (note that this point may not work on all installations).
Save the code below in the file /userdata/system/configs/game_state_changer.py.
Puis accordez les droits d'exécution :
Save the code below in the file /userdata/system/configs/game_state_changer.sh.
Puis accordez les droits d'exécution :
To capture keys on Batocera, create the file /share/system/configs/multimedia_keys.conf.
This file is automatically sought and loaded at start -up, nothing else to do.
BTN_BASE3 1 python /userdata/system/configs/game_state_changer.py 1
BTN_BASE4 1 python /userdata/system/configs/game_state_changer.py 2
BTN_BASE3 1 /userdata/system/configs/game_state_changer.sh
BTN_BASE4 1 /userdata/system/configs/game_state_changer.sh
Batocera needs to be restarted so that the configuration of the keys is effective.
Once a game is launched, if you press 'save' or 'load' button, you should have a message at the bottom of the screen indicating this condition.
![]() ![]() | ![]() | ![]() |