How to remap the multimedia keys for function keys on this bluetooth keyboard

keyboard-layout

I got a Logitech Bluetooth Multi-Device Keyboard K480 and after installing it just by following the bluetooth pairing, the default settings will leave the function keys mapped as multimedia keys, so I have to hold fn to access F1,F2,F3, etc.

That is very counter-intuitive for me, and I'd like to remap it so I can access Functions directly and access the multimedia keys with fn

Logitech Bluetooth Multi-Device Keyboard K480

This is F1 without holding fn and then holding it.

KeyPress event, serial 37, synthetic NO, window 0x4e00001,
root 0xd6, subw 0x0, time 63445847, (-438,408), root:(284,460),
state 0x10, keycode 180 (keysym 0x1008ff18, XF86HomePage), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x4e00001,
root 0xd6, subw 0x0, time 63445922, (-438,408), root:(284,460),
state 0x10, keycode 180 (keysym 0x1008ff18, XF86HomePage), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x4e00001,
root 0xd6, subw 0x0, time 63446510, (-438,408), root:(284,460),
state 0x10, keycode 67 (keysym 0xffbe, F1), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x4e00001,
root 0xd6, subw 0x0, time 63446597, (-438,408), root:(284,460),
state 0x10, keycode 67 (keysym 0xffbe, F1), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

Best Answer

It seems that logitech provides a special driver on various OS's other than Linux that does exactly this swap by sending an undocumented magic command to the keyboard.

Some people have monitored the communication to find the codes sent to some other similar logitech keyboards such as the 760 and the 810. You might try one of those.

Failing that, you can use xmodmap to swap the key assignments. We see that your keyboard sends 2 different keycodes depending on whether Fn is pressed or not. Use xmodmap -pke to list all the key mappings in a file, then keep just the ones referring to the wanted keycodes. For example you would have

keycode  67 = F1 F1 F1 F1 F1 F1 XF86Switch_VT_1
keycode 180 = XF86HomePage NoSymbol XF86HomePage

and so on. Simply invert the numbers:

keycode 180 = F1 F1 F1 F1 F1 F1 XF86Switch_VT_1
keycode  67 = XF86HomePage NoSymbol XF86HomePage

Then pass this filename as argument to xmodmap to have it update the mapping.

Related Question