Mapping sound volume up down to Picade controls

Hello, I have a Picade based on MAME and Attract Mode only installed on a standard Bookworm Lite. It works perfectly. I can also manage the sound level from the terminal using the alsamixer command. But I can’t manage it directly from Attract Mode or Mame. I would like to assing Volume with the Button 1 (Left control) + Joystick Up to increase the volume and Btn1+Joy Down to decrease. I tried using the bind or trap command executed from a background service but it doesn’t work. Is there anyone who made this possible with bookworm lite without retropie or an other embedded system. Any help would be greatly appreciated.

OK, I solved the issue.

1st: Install triggerhappy :
sudo apt install triggerhappy

2nd: Check the keys and event number you want to assign. Start the command:
thd --dump /dev/input/event*
and do the manipulation you want to address with your controls. The result will display in the terminal:

EV_KEY  KEY_LEFTCTRL    1       /dev/input/event0
# KEY_LEFTCTRL  1       command
EV_KEY  KEY_UP  1       /dev/input/event0
# KEY_LEFTCTRL+KEY_UP   1       command
EV_KEY  KEY_UP  0       /dev/input/event0
# KEY_LEFTCTRL+KEY_UP   0       command
EV_KEY  KEY_LEFTCTRL    0       /dev/input/event0
# KEY_LEFTCTRL  0       command

3rd: Create a configuration file for the service. The name is not important but must finished with ‘.conf’ :
sudo nano /etc/triggerhappy/triggers.d/audio.conf
Add the following lines in the configuration file:

KEY_UP+KEY_LEFTCTRL     1      /usr/bin/amixer set PCM 5%+
KEY_DOWN+KEY_LEFTCTRL   1      /usr/bin/amixer set PCM 5%-

It’s very important, to place KEY_UP or KEY_DOWN first. If you do it by the other way meaning KEY_LEFTCTRL first, you will have to push up the joystick first then press the button.

4th: Change the service user from ‘nobody’ to ‘pi’. Edit the service with command
sudo systemctl edit triggerhappy.service --force --full

and change the ‘–user’ parameter of the ‘ExecStart’ command to ‘pi’

ExecStart=/usr/sbin/thd --triggers /etc/triggerhappy/triggers.d/ --socket /run/thd.socket --user pi --deviceglob /dev/input/event*

5th: Restart the service.
sudo systemctl restart triggerhappy.service

6th: Test the result. Start the alsamixer with the command:
alsamixer
Execute your control combo and you will see the alsamixer cursor moving up and down.

That’s it!

For information: The keyboard keycode can be found in your system at ‘/usr/include/linux/input-event-codes.h’. An online version is visible at this place

Based on those info, the mapping i made for the picade in the ‘/boot/firmware/config.txt’ is:

[all]

dtoverlay=picade
dtparam=audio=off
dtparam=up=103
dtparam=down=108
dtparam=left=105
dtparam=right=106
dtparam=button1=29
dtparam=button2=56
dtparam=button3=57
dtparam=button4=42
dtparam=button5=25
dtparam=button6=15
dtparam=enter=28
dtparam=escape=1
dtparam=coin=6
dtparam=start=2

which corresponds to:

Picade Control Key Code
Joystick Up KEY_UP 103
Joystick Down KEY_DOWN 108
Joystick Left KEY_LEFT 105
Joystick Right KEY_RIGHT 106
Button 1 KEY_LEFTCTRL 29
Button 2 KEY_LEFTALT 56
Button 3 KEY_SPACE 57
Button 4 KEY_LEFTSHIFT 42
Button 5 KEY_P 25
Button 6 KEY_TAB 15
Right side (Enter) KEY_ENTER 15
Left side (Escape) KEY_ESC 1
Front Right (Coin) KEY_5 6
Front Left (Start) KEY_1 2