Scripting Function Keys

Many input devices nowadays include dedicated function keys for particular (usually hardware-related) functions, such as volume adjustment, brightness adjustment, power off, etc. Batocera supports the scripting of any key to any command, and includes most common function keys for various platforms. But it is possible that your device in particular doesn't have these coded in yet, or you simply want to change what the function key does. This can be achieved via the configuration of triggerhappy.

To create a custom configuration that is overlaid on top of the default function keys:

  1. Refer to the list of existing configurations at https://github.com/batocera-linux/batocera.linux/tree/master/package/batocera/core/batocera-triggerhappy/conf and place the ones you'd like to edit into a file named multimedia_keys.conf.

    If you'd like to see these files on your local installation:

    1. Connect to your Batocera machine either by SSH or by WinSCP (any method that lets you see the root of the system).
    2. Navigate to /etc/triggerhappy/triggers.d/ and find the multimedia_key_<device name>.conf for your device.
  2. Copy the file to /userdata/system/configs/multimedia_keys.conf.
  3. Make your appropriate edits to it and save it.

Your custom multimedia_keys.conf file's configuration will be overlaid on top of the default profile. If there are conflicting settings, the one in /userdata/system/configs/multimedia_keys.conf will take priority.

For example:

multimedia_keys.conf
BTN_TRIGGER_HAPPY3 1            batocera-brightness - 5
BTN_TRIGGER_HAPPY4 1            batocera-brightness + 5
KEY_MUTE 1                      batocera-audio setSystemVolume mute-toggle
KEY_VOLUMEUP 1                  batocera-audio setSystemVolume +5
KEY_VOLUMEDOWN 1                batocera-audio setSystemVolume -5
# power off, switch command to "/usr/sbin/pm-suspend" to go into suspend mode instead (suspend mode is currently unused in Batocera)
KEY_POWER       1               /sbin/shutdown -h now
# display some information on X displays
KEY_F2          1               /usr/bin/batocera-info --short | HOME=/userdata/system XAUTHORITY=/var/lib/.Xauthority DISPLAY=:0.0 osd_cat -f -*-*-bold-*-*-*-38-120-*-*-*-*-*-* -cred -s 3 -d 4

You could also check for various hardware states, such as if there is a device plugged into the headphone jack:

multimedia_keys.conf
SW_HEADPHONE_INSERT 0           batocera-audio set headphone
SW_HEADPHONE_INSERT 1           batocera-audio set speakers

Reboot the device to apply the new triggerhappy configuration.

Open a terminal and type the following command:

evtest

Then select your intended controller and press the button on your controller. The detected input will then be displayed like so:

Event: time 1614795871.549381, type 1 (EV_KEY), code 99 (KEY_SYSRQ), value 0

Look for the key name in parenthesis and its value when depressed after the “code” number. In this example, the key name would be KEY_SYSRQ and its value would be 0.

A list of most existing events can also be found in the keys section of the evmapy page.

All default configurations are at https://github.com/batocera-linux/batocera.linux/tree/master/package/batocera/core/batocera-triggerhappy/conf, but in case either you can't figure out which one applies to your machine or you'd just like some security you can check the file on your machine at /etc/triggerhappy/triggers.d.

  • scripting_function_keys.txt
  • Last modified: 5 months ago
  • by atari