I have just upgraded to 20.04. When I try to assign a media key to a Custom Shortcut or any shortcut except in the group Sound and Media, the settings window does not register the key press, and instead it controls the volume directly. It used to work well in 18.04. Is this normal, and is there any way to get it to work?
-
why the keys are not registered is bcoz they already have the commands to do. you can deactive them via xmodmap and then it will register.. – PRATAP May 22 '20 at 07:52
-
https://askubuntu.com/q/1184094/739431 – PRATAP May 22 '20 at 07:54
-
Thanks for the pointer. There's something strange going on. I'm able to assign Audio raise volume key now. Will log out/in and check. – Marius Bjørnstad May 22 '20 at 08:01
-
After log out/in, none of the keys are able to assign again. They just control the volume directly when I try to assign them. I think I can use the example with xmodmap (if that still works on 20.04), to remap the volume keys so some unused key, and then assign that to my script. – Marius Bjørnstad May 22 '20 at 08:05
-
1yes.. using xmodmap get the keycode and make it to null.. then you can assign a shortcut with that key.. i did it with all the GNOME versions starting from 17.10 – PRATAP May 22 '20 at 08:09
2 Answers
KMonad was the first thing I tried that worked for me. You could try their binary download. I built from source with their dev container.
Follow the commands from the faq:
sudo groupadd uinput
sudo usermod -aG input $USER
sudo usermod -aG uinput $USER
# Then log out for groups to take effect
Place the following in /etc/udev/rules.d/kmod.rules
KERNEL=="uinput", MODE="0660", GROUP="uinput", OPTIONS+="static_node=uinput"
Find what keyboard device to modify: ls -1 ls /dev/input/by-id/
.
I had the following output:
usb-CN00XMGG8LG001CMDJ3JA04_Integrated_Webcam_HD_200901010001-event-if00
usb-CN00XMGG8LG001CMDJ3JA04_Integrated_Webcam_HD_200901010001-event-if02
usb-Logitech_Gaming_Keyboard_G213_085338673338-event-kbd
usb-Logitech_Gaming_Keyboard_G213_085338673338-if01-event-kbd
usb-Logitech_USB_Receiver-if02-event-mouse
usb-Logitech_USB_Receiver-if02-mouse
I have 2 "Logitech_Gaming_Keyboard_" entries. The "if01-event" one is the one I need. As suggested by the docs, [apt install
] evtest
can help narrow down devices. Media keys wouldn't even reach xev
, but did show up when testing the correct device with evtest
.
Customize a config file. The input
line needs to be set to your device. See the tutorial file for details. Here is my foo.kbd
:
(defcfg
;; Not this one. That's all the normal keys.
;; input (device-file "/dev/input/by-id/usb-Logitech_Gaming_Keyboard_G213_085338673338-event-kbd")
input (device-file "/dev/input/by-id/usb-Logitech_Gaming_Keyboard_G213_085338673338-if01-event-kbd")
output (uinput-sink "My KMonad output" )
fallthrough true
)
;; https://github.com/kmonad/kmonad/blob/master/src/KMonad/Keyboard/Keycode.hs
;; , (KeyVolumeDown, ["voldwn", "vold"])
;; , (KeyVolumeUp, ["volu"])
;; , (KeyNextSong, ["next"])
;; , (KeyPlayPause, ["pp"])
;; , (KeyPreviousSong, ["prev"])
;; Nothing for KeyStopCd
;; KeyMute -> mute
(defsrc
;; mute vold volu
pp stopcd prev next
)
;; Ubuntu 20.04/gnome/wayland eats f13, f20, f21, f22, f23
;; f24 just doesn't work.
;; That leaves f14-19 open.
(deflayer name
;; f18 f19 f24
f14 f15 f16 f17
)
Test it out:
./kmonad ./foo.kbd
While kmonad is running:
- The redefined keys should not trigger media actions
xev
will respond to key presses, but will call the keys something likeXF86Launch5
- Gnome Settings - Keyboard Shortcuts will allow using these keys in shortcuts. Will display
Launch5
as the key. Test it out with the Launch calculator shortcut. - The keys can be used to bind a shortcut in vscode. They will show up as
f14
and the like.
Once it is working, kmonad can be set to run at startup by your preferred means.
Tested with Ubuntu 20.04 / Wayland / gnome 3.36.8
I had no luck trying solutions involving xmodmap or setxkbmap. This answer works around other systems by rewriting the inputs first. But it still runs into Ubuntu using random extended f keys: Cannot disable `Tools` keybinding on 20.04
Please show me a simpler solution that just works lol

- 111
Here's an outline of a procedure to make the mute and volume keys do something else. It breaks if you change the keyboard layout, e.g. if you switch between two languages.
- Make an xmodmap file that describes the key remapping. Typically it's a file called
.Xmodmap
in the home directory, but it could be called anything. The content should be:
keysym XF86AudioMute = XF86Launch5
keysym XF86AudioLowerVolume = XF86Launch6
keysym XF86AudioRaiseVolume = XF86Launch7
(1b: You can test it by running `xmodmap ~/.Xmodmap. It should produce no output, and the volume keys should no longer do anything)
- pen Startup Applications on the desktop (Search for it). Add an entry to run
/usr/bin/xmodmap /home/username/.Xmodmap
. Replace "username" with your own username (the usual $HOME or ~ won't work because the command field is not a shell).
- Now you can map the volume keys to other actions in the settings

- 348
-
-
Yes this only works on X11, not wayland. Great that you found a solution and described it! (I changed my setup and don't remap these keys any more) – Marius Bjørnstad Mar 28 '23 at 20:23