Need help binding multimedia keys to correct keycodes

Hello all,
First off, I understand that this can be achieved with xmodmap, but I read of some compatibility issues with sxhdkrc so I have been reluctant to try.
I have recently installed endeavour bspwm and am having issues with the brightness keys on my laptop. In Sxhdkrc its under:

XF86MonBrightnessUp
xbacklight -inc 5

XF86MonBrightnessDown
xbacklight -dec 5

After I saw this I tried using the xbacklight commands and they work, albeit only in sudo (maybe that’s the problem?).

The keys I wish to bind show up in sudo showkey & sudo showkey -s as:

Brightness up
keycode 225 press
keycode 225 release
0xe0 0x54 0xe0 0xd4

Brightness down
keycode 224 press
keycode 224 release
0xe0 0x4c 0xe0 0xcc

I thought it was strange that the scan codes were in groups of 4, which made it worse when I eventually tried to change the X keysms config file and realized my codes were much shorter than the ones in those mappings.

Can anyone show me how I can change the values behind the XF86MonBrightnessUp key and other media keys?


Second Issue:
The mappings for my volume keys are correct however they are jumping to around 35% volume from mute with only one press, then climb up at strange rates from there. In sudo showkey -s I noticed that those keys also were showing 4 outputs. Could this be a reason why?
I also noticed that in the polybar config file there were lines stating:

; Interval for volume increase/decrease (in percent points)
; Default: 5
interval = 5

Think you need to add yourself to the video group.

Also this may help:
Backlight - ArchWiki (archlinux.org)

1 Like

Consider myself added :slight_smile:
I figured it out in the end, I have to change the xkb config files. The sudo was not the issue, just incorrect mappings.
Now to painstakingly create an xkb file :slight_smile:

1 Like

These things helped me when I was mapping some keys on my Compaq keyboard. May be some useful info there.

https://wiki.archlinux.org/title/xmodmap

To remap the extra internet keys of a Compaq keyboard I looked at theCompaq section of:
/usr/share/X11/xbd/symbols/inet
for ideas of key names.

xmodmap -pk print keymap table
xmodmap -pke print keymap table as expressions
1 Like

I require some help on this topic as well. I am also running bspwm, though I believe it’s not the root of the issue. The Multimedia Keys (Next, Play/Pause, Prev) dont work on my keyboard. I’ve spent a lot of time trying to fix this, but changing keyboard layouts is a very confusing area with many different commands i can barely tell apart.

With showkey -k the media keys return keycodes 163 through 165. when looking at xmodmap -pke, i see that these keycodes have some random “XF86 launch mail” or something like that assigned. The commands XF86Audio{Next,Play,Pause,Prev} sit on different keycodes, 171 through 173.

After i found that out, i thought it would be as easy a solution as reassigning the commands to the right keycodes, so I did just that via xmodmap -e "keycode 165 = XF86AudioNext NoSymbol XF86AudioNext". The repetition of these values is copied straight from the other line. And it does not work.

So I checked the key signal of my media keys via showkey -s and got

0xe0 0x10 0xe0 0x90 
0xe0 0x22 0xe0 0xa2 
0xe0 0x19 0xe0 0x99

so 4 signals per key instead of 3. Since i figured the 0xe0 sections of this result need to be aligned with a “NoSymbol” string in the xmodmap -e command, I added that to the start of the keycode command, but it made no difference.

Now, I’ve read a lot of guides and forum stuff and my head is buzzing with all the input. Someone said you need to substract 8 from the keycode since the kernel adds 8, so i assigned the “audioNext” thing to keycode 157 as well (so that it would land on 165 aka my next song key), but that ALSO didnt work. I’m trying hard but its getting frustrating.

For Info, i’m using a logitech g915 wireless keyboard. i tried setting the keyboard model to “logitech_base” via setxkbmap -model logitech_base, but couldnt tell a difference in the keymap. didnt get the media keys working either.

Maybe one of you has an idea how to do this the right way? Thanks in advance.

EDIT: just installed xev to check the keys and now my confusion is even worse. when testing my media keys in there, they report the, presumably correct, keycodes of 171-173, as well as the XF86Audio… commands. If thats so, why dont they work, and why do other programs report different keycodes?
I thought I remembered the keys working at some point, but figured i had something confused. now im not so sure anymore.

Why you’re getting different code is that the X system has its own keyboard-handling layer, and X associates different “keycodes” with keys than your Linux base system does. The showkey command is showing you the keycodes in Linux-base-system lingo. For xmodmap you need the X keycodes, which are what xev is displaying. So long as you’re planning to work in X and do your key rebinding with xmodmap, then, ignore showkeys and just listen to what xev says.

You may find your answer here:
https://wiki.linuxquestions.org/wiki/Configuring_keyboards#Enabling_Keyboard_Multimedia_Keys

And you could also try Xbindkeys:
https://wiki.archlinux.org/title/Xbindkeys

well, that clarifies it a whole lot. but it doesnt explain why the media keys dont work properly. I’ve done some more testing since your post, and found the following:

  1. Checking xev, my media keys return key codes 171 - 173
  2. in xmodmap -pke, these keys have their audio actions assigned

now, most confusingly, when testing the keyboard inside my browser with a keyboard testing website, it also shows the media keys when pressed. so the keys are being detected normally by the system. but when on youtube, spotify, or in media apps like spotify-player (tui client for spotify), pressing the media keys does nothing
even worse, the keys do work in mpv. so now im confused again. how can that be?

for reference, here are the signals / commands assigned to the media keys:

$ xmodmap -pke | grep -G "17[1-3]"
keycode 171 = XF86AudioNext NoSymbol XF86AudioNext
keycode 172 = XF86AudioPlay XF86AudioPause XF86AudioPlay XF86AudioPause
keycode 173 = XF86AudioPrev NoSymbol XF86AudioPrev

as well as an excerpt taken from xev:

KeyPress event, serial 33, synthetic NO, window 0x4600001,
    root 0x1ec, subw 0x0, time 1015788, (678,271), root:(2747,1154),
    state 0x0, keycode 173 (keysym 0x1008ff16, XF86AudioPrev), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False