0x79 - a blog

Work in progress.

Raspberry Pi: Use volume keys on keyboard with triggerhappy

To use the volume keys on your keyboard on linux or with a raspberry pi in particular, you can use the triggerhappy package, which comes pre-installed with raspbian.

The trigger happy config has to be saved at `/etc/triggerhappy/triggers.d/*.conf. We first specify the key, followed by the corresponding action to take.

KEY_VOLUMEUP    1      /usr/bin/amixer -M set PCM 5%+
KEY_VOLUMEUP    2      /usr/bin/amixer -M set PCM 5%+
KEY_VOLUMEDOWN  1      /usr/bin/amixer -M set PCM 5%-
KEY_VOLUMEDOWN  2      /usr/bin/amixer -M set PCM 5%-
KEY_MIN_INTERESTING  1 /usr/bin/amixer set PCM 1+ toggle

Some notes:

  • use absolute paths
  • use the -M parameter on amixer, otherwise the volume will jump like crazy(e.g. from mute to 91% with one key-press). From the man page: "-M Use the mapped volume for evaluating the percentage representation like alsamixer, to be more natural for human ear."
  • We map the up and down volume keys twice, because (1) is used for a single press and (2) for continued pressing of the key, so we can keep the key pressed to get bigger changes in volume.

Restart the trigger happy demon after you have edited the configuration:

systemctl restart triggerhappy

You can also find the correct names of specific keys with

thd --dump /dev/input/event*

or watch commands and their output being executed with

thd --triggers /etc/triggerhappy/triggers.d/ /dev/input/event*