xmodmap for key combination - how to toggle the Fn behavior?

81

Solution 1

xev can't show events that are captured by the desktop environment. A better way to test keys is using showkey command (at the Linux console, not inside X11). I'm guessing that the OS is actually receiving a Shift + Super + some-key combination.

Though you could conceivably remap said combination to just an F key, it would likely be troublesome: you'd have to "release" the Shift key (because the keyboard simulates pressing it), and making Shift+F1 work would be even more complicated, as it would require tracking if the Shift key was held down previously.

This problem is very common on laptops, which often have either a key combination to toggle multimedia hotkeys, or an option in their BIOS/firmware. But as you mentioned that this is concerning a specific model of external keyboard, looking online I found this project:

https://github.com/milgner/k290-fnkeyctl

The project's description states that it "reconfigures the way the function keys on Logitech K290 keyboards work", so it may be worth giving a try.

Solution 2

I obtained the same result by swapping the keycodes between Fn+Fx and Fx where x is 1,2,...12.

  1. Use xmodmap -pke to obtain a list of the current keycodes and keysymbols.
  2. Then run xev and press F1 through F12 keeping note of its keycode.
  3. Then make the swap in your ~/.Xmodmap file.

For e.g. in my system the result of (1):

keycode 67 = F1 F1 F1 F1 F1 F1 XF86Switch_VT_1
keycode 68 = F2 F2 F2 F2 F2 F2 XF86Switch_VT_2
keycode 69 = F3 F3 F3 F3 F3 F3 XF86Switch_VT_3
keycode 70 = F4 F4 F4 F4 F4 F4 XF86Switch_VT_4
...

keycode 121 = XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 198 = XF86AudioMicMute NoSymbol XF86AudioMicMute
..

Then I swapped it in ~/.Xmodmap:

keycode 121 = F1 F1 F1 F1 F1 F1 XF86Switch_VT_1
keycode 122 = F2 F2 F2 F2 F2 F2 XF86Switch_VT_2
keycode 123 = F3 F3 F3 F3 F3 F3 XF86Switch_VT_3
keycode 198 = F4 F4 F4 F4 F4 F4 XF86Switch_VT_4
...


keycode 67 = XF86AudioMute NoSymbol XF86AudioMute
keycode 68 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 69 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 70 = XF86AudioMicMute NoSymbol XF86AudioMicMute
...

Then to take affect run xmodmap ~/.Xmodmap.

Share:
81
Imran
Author by

Imran

Updated on September 18, 2022

Comments

  • Imran
    Imran over 1 year

    I am just wondering if we can show ads (coming from Admob, iAds etc) in 3D view rather than 2D ads popping from top or bottom.

    I have a 3D racing game which is currently running in iOS devices and am looking to put some ads in 3D world. I am not sure even its possible :p

    Any suggestions!

    Regards

    • ThomasW
      ThomasW almost 12 years
      Do you want to put the 2D ad banners on surfaces of the 3D views in your app?
    • 9000
      9000 over 10 years
      Usually <kbd>Fn</kbd> works on keyboard's hardware level. Hopefully keycodes, as opposed to keysyms, of F-keys still differ when it is not pressed. Can you please run xev once more and paste the output for two different F-keys?
    • user55574
      user55574 about 10 years
      Sadly, Solaar only works for wireless emitters, not wired ones :(
    • Jonas Berlin
      Jonas Berlin almost 6 years
      I would start by looking in the BIOS settings. Some allow swapping the Fn key e.g. F-keys-by-default..
    • Jonas Berlin
      Jonas Berlin almost 6 years
      really nasty that F1 reuses keycode 50, so you can't just change what 50 does either.. :P