The "Fn" key is local.

You've come to this page because you've asked a question similar to the following:

What is the scancode/HID "usage" for my Fn key? Why isn't it on the layout diagrams for my keyboard maps? Why can I not re-map it to another physical position?

This is the Frequently Given Answer to such questions.

The Fn key is entirely local. It does not appear on keyboard layouts because as far as the operating system is concerned, it does not exist. It is handled entirely by the microprocessor in the keyboard itself. Knowledge of it is not sent over the wire, between your keyboard and your computer. There's no USB HID "usage" denoting it. It has no scancode in the old PS/2, PC/AT, PC/XT keyboard device architecture.

The point of the Fn key is to reduce keyboard size by doubling up physical keys. A full "multimedia" keyboard nowadays has upwards of 124 keys, in 7 rows. The Fn key allows, amongst other things, doubling up the function keys on row K as multimedia keys from row L/M, and doubling up various keys in the main keypad as keys from the cursor and editing keypads. This is commonly employed on laptop and other size-constrained keyboards.

The keyboard microprocessor handles your Fn key as an entirely local modifier key. It has an internal "Fn shift" state, and the action of the Fn key is to set that shift state. It uses the current "Fn shift" state to determine the usages/scancodes that are sent over the wire for other keys, including the keys that double-up as both function keys and (say) multimedia keys. This is why on some keyboards one needs to press (say) the chord Fn+F4 to actually get function key 4 sent over the wire.

In fact, laptop and suchlike keyboards usually have two such local modifiers. The other is the state of the NumLock LED (sic), making every key have four different ways in which it can be handled. In a number of modern keyboard microprocessors, there are thus four entirely internal maps, not to be confused with the keyboard maps on the host at the operating system level, from physical keys to actions taken by the microprocessor.

Some people explain this as the Fn key being special in hardware. This is not so. In fact all keys work the same way. They are all connected to the on-board microprocessor, and the maps in the microprocessor's ROM determine what the microprocessor does when each switch in the physical keyboard matrix is closed. Sometimes (as is the case for the Fn key) all of the actions are local in all maps; sometimes all of the actions are to send information (USB input reports with HID "usages", or PS/2 scancodes, listed in the maps) out over the wire; in a few rare cases they do a mixture of both.

On many such (but not all) keyboards the microprocessor also implements a Fn Lock. Like ⇫ Shift Lock does for ⇧ Shift, Fn Lock sets the sense of the Fn shift state. When the lock is on, the sense is inverted. On some keyboards, there is even a Fn Lock key chord, a doubled-up also local meaning for another key, such as Fn+⇬ Capitals Lock. (This makes ⇬ Capitals Lock one of the rare keys aforementioned whose actions by the microprocessor are sometimes local and sometimes not.)

As seen by your computer, at the other end of the wire, all of this is invisible. Your computer sees a full keyboard with a real, independent F4 key. That is what X applications see in X input events, and what is seen at a low level in PS/2 keyboard device and USB HID drivers.

For some keyboards with Fn Lock, the manufacturer also provides a vendor-private USB HID output report mechanism for setting it from the host. This mechanism is what a machine firmware's SETUP utility invokes when it lets you switch Fn Lock, and what utilities like the Lenovo Keyboard "Driver" invoke on Windows. Logitech documents its vendor-private protocol as part of something that it calls "HID++", and there are a few third-party utilities for talking to Logitech "HID++" devices. (However, and sadly, Logitech does not document exactly what feature flags correspond to "Fn inversion", and the third-party utilities list three different ones, indicating that even Logitech didn't make a single universal feature for its own devices.) Outwith this, though, operating systems and applications have no knowledge of Fn.

Further reading

© Copyright 2020 Jonathan de Boyne Pollard. "Moral" rights asserted.
Permission is hereby granted to copy and to distribute this web page in its original, unmodified form as long as its last modification datestamp is preserved.