22

I like to know how Fn keys work in my laptop. I think a kernel module exist that catch Fn key and call some scripts to do something. In my laptop, Fn+F2 switch power of wireless and blue-tooth.

this is output of acpi_listen, when i press Fn+F2

hotkey ATKD 0000005d 00000019
hotkey ATKD 0000007e 00000009

and, folloing is output of xev for Fn+F2

keycode 238 press
keycode 238 release
keycode 237 press
keycode 237 release

I guess whenever i pressed Fn+F2 two events are jumped out. I tried to find what actions are executed for this keys. any idea appreciated ;)

22

Synetech gives a very readable explanation about the Fn keys here

Technical Details

When you press a key on a keyboard, the keyboard controller (a small IC chip inside the keyboard) detects the electrical circuit and processes it to decode which key was pressed and then sends the scancode to the motherboard. The operating system receives scancode from the BIOS and then performs whatever action it needs to in order to process that keypress.

With most keys, this is simple enough. If you press the A key, its keyboard controller sends the scancode to the motherboard which then passes it to the OS which in turn usually prints 'A'. (If the OS detects that one of the modifier keys is currently held down, then it may do something different. In fact, you can configure it to do whatever you want when the A key is pressed with or without modifiers.)

Now the Fn key is special. When you press it by itself, nothing happens because it is exclusively a modifier key and is not (generally) meant to do anything on its own. When you hold it and press another key, the keyboard controller detects that and looks in its built-in table to see if it is a known combination. If the combo is not in the table, then it just ignores it, but if the combo is in the table, then it looks up the associated scancode and sends that.

What does the OS end up seeing? It does not see the scancode for the Fn key and the scancode for the other key. Instead, it sees a single scancode associated with whatever function the Fn-combo has been set to. For example, if the laptop manufacturer has set the Fn+Down Arrow combo to reduce the volume, then the OS sees the scancode associated with the Volume Down, which some keyboards actually have.

Also note that the Fn key works independently from the operating system.

Moreover, this article may help point you in the right direction:

The kernel has its own scancode to keycode mapping table, so it maps a certain scancode to a keycode. You can look into /usr/include/linux/input.h to see what your kernel uses for scancode to keycode mapping – it is called a keymap.


Postscript

I might need to somewhat renege on the earlier claim that the Fn keys work entirely independently of the OS; without going into more technical details here, the upshot seems to be that your OS might not "support" all or some of your keyboard's Fn keys, see, for instance:

  • 1
    Thanks, interesting information about Fn keys, Actually I want find what part of OS handle scancode associated with, for example, "keycode 238". – soroosh Mar 20 '13 at 14:37
  • 3
    Maybe this article can help point you in the right direction? "The kernel has its own scancode to keycode mapping table, so it maps a certain scancode to a keycode. You can look into /usr/include/linux/input.h to see what your kernel uses for scancode to keycode mapping – it is called a keymap." – nutty about natty Mar 20 '13 at 14:46
  • 1
    That article is perfect, This is what I'm looking for – soroosh Mar 20 '13 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.