What happens when you press an extra key on a keyboard

driverskeyboard

I am interested in knowing how a keyboard with extra keys work. So for example say I have the following keyboard:

enter image description here

You can see that it has extra keys. Now say that I pressed the mute key, what will happen in this case?

This is what I think happens:

  • A signal will be sent to the computer.
  • The keyboard device driver will receive this signal.
  • The keyboard device driver will see that this signal is the mute signal, so it will not pass it to the OS, but rather it will call an OS function/system call that will mute the sound on the computer.

Am I correct?

Best Answer

Very brief overview over the input layers:

Your keyboard device is connected to the PC in some way, for example via USB, or a PS/2 port. The kernel drivers for this mechanism know how to handle communication when a key is pressed on the keyboard.

For an USB keyboard, a standard called HID (Human Interface Device) exist. This is not only for keyboards, but also for mice, joysticks and other input devices. So the device will have a descriptor telling the kernel what kind of signals it can emit, and a lot of the codes for keys including mute are standardized.

Nevertheless, some keyboards have keys that are not standardized (like the Fn on some keyboard), and it's up to the manufacturer how it signals those keys.

There's a special layer in the kernel for handling HID devices. This layer makes the raw HID comunication available at /dev/hidrawX, and then goes on to translate the HID events into kernel input events.

The kernel input layer takes scan codes (numbers corresponding to a physical key, unique to the deivce) and converts them into key codes (numbers corresponding to logical keys standardized over all devices). Both are made available as events on/dev/input/eventX. You can use evdev to see these events, and showkey, dumpkeys etc. to see the translation table.

The X server (or Wayland) reads all those events, and translates them into key symbols (like a, รก etc., or special ones like AudioMute). X applications can receive this symbols, and act accordingly. You can use see xev application to see this layer, and configure it with xmodmap and the xkbd specification in your xorg.conf.

To react to AudioMute, some application is needed for it. Often, this is the Window Manager, but if your Window Manager doesn't do it, a separate application will also work.

So there's no single "keyboard driver", it's a lot more complicated, and there's not special call for "mute".