Ask Your Question

How can i find out if the user has pressed the FN key ?

asked 2017-05-19 03:48:57 +0200

librebel gravatar image

How can i find out if the user has pressed the FN key ?

For example when i press FN+DELETE, i get a KeyPress event with .Modifiers=0 and .KeyCode=0 and .KeyFunc=0 ...

But when i press only DELETE, i get a KeyPress event with .Modifiers=0 and .KeyCode=1286 and .KeyFunc=13 ...

If the FN-key is considered as a Modifier key, then why is there no constant for the FN-key among the constants?

Thanks in advance, lib

edit retag flag offensive close merge delete



Fn generates no event on my laptop. Considering what I've done to customise my keyboard and xkb specification, I wonder if Fn is directly handled by keyboard electronics and only the resulting remapping sent to OS driver.

Under Linux, I don't see Fn with dmesg|tail nor with showkey, but keycode for Fn+key is different from key alone.

In your script, test for the combined keycode without modifier (unless you also press a standard one).

ajlittoz gravatar imageajlittoz ( 2017-05-19 08:23:56 +0200 )edit

Thanks for your reply @ajlittoz, it is precisely as i experienced too: 1) the FN-key itself is not registered in ANY key-event, neither as Modifier nor as KeyCode nor as Char, 2) but pressing the the FN-key can still alter other key-events, like a Modifier does. For example if i type FN+p on my keyboard, it generates a .KeyCode=1289 and .KeyChar=*, and prints the character "*" . On Wikipedia the FN-key is described as a Modifier Key.

librebel gravatar imagelibrebel ( 2017-05-19 10:15:47 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-05-19 17:33:44 +0200

peterwt gravatar image

In a way you answered your own question in the link to Wikipedia. It does say Fn is a modifier key but goes on to say that it is a form of meta-modifier key in that it causes the operating system to see altered scancodes when other keys on the keyboard are pressed. It is most common for the Fn key processing to happen directly in the keyboard micro-controller. So the Fn key pressed on its own is meaningless. You need to test for the key codes for the function key that is to be used.

edit flag offensive delete link more


Thank you @peterwt, this definitely answers my question.

librebel gravatar imagelibrebel ( 2017-05-19 18:53:50 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-05-19 03:48:57 +0200

Seen: 313 times

Last updated: May 19 '17