Volume keys for the Raspberry Pi

September 2nd, 2025

After wasting a couple of evenings trying to assign my own volume control keys (F8/F9) for the Raspberry Pi 400, I finally found an acceptable solution. Most of that time was lost with Triggerhappy, which kind of worked but did not delete the events from the queue. Therefore, the keypresses still ended up doing unwanted things in running programs. Moreover, getting the daemon to work properly was so tricky that I wonder why it’s installed in the first place. In good old X11 it wouldn’t take long to remap the keycodes to XF86VolumeRaise and XF86VolumeLower using xmodmap, but the Raspberry Pi OS uses Wayland these days, so no go. The compositor (kind of like the window manager in X) is Labwc.

After trying to remap F8/F9 with xmodmap I soon realized Wayland deals very differently with the keyboard than X11 – nothing happened. Finally, I added the following modification to .config/labwc/rc.xml (inside the openbox_config tag):

<keyboard>
	<repeatRate>25</repeatRate>
	<repeatDelay>438</repeatDelay>

	<keybind key="F8">
		<action name="Execute">
			<command>amixer sset Master 5%-</command>
		</action>
	</keybind>
	<keybind key="F9">
		<action name="Execute">
			<command>amixer sset Master 5%+</command>
		</action>
	</keybind>
</keyboard>

At that point I had pretty much given up hope already, but lo and behold: the kludge worked! Volume could be controlled with the respective keys, which were also grabbed by Labwc and didn’t turn into extraneous keypresses. No need to reboot even, as “killall -HUP labwc” reloads the configuration file. In some earlier OS versions the configuration file has apparently been in a different location or with a different name, but this is where it resides at least for now.

As the keyboard has a Fn key anyway, it would have been a minimal effort to simply add various media keys as extras behind the normal function keys, as seen on many laptops. F11, F12 and the power button are there already exactly like that. For some unknown reason, Raspi designers didn’t deem media keys as necessary, which lead to this somewhat tiresome (if educative) effort. Sigh.

Filed under: linux,softat

Kommentin kirjoitus

You must be logged in to post a comment.

RSS feed for comments on this post.


Kommenttien virta

Aiheet