I'm trying to write a kernel driver to support a hardware switch on my laptop. The switch is supposed to control whether or not the touchpad is disabled or enabled, and it is built into the laptop's 360° hinge. Taking a cue from other drivers for nearly identical hardware, I'm catching the hardware events from the switch, and depending on the position of the switch, I'm sending out corresponding keycodes on an input device. The keycodes are left to be handled in user space. This is the same mechanism I've observed being used in the Windows 10 driver for this switch.

I've found that I can send keycode 191 (KEY_F21), and Gnome 3.18 successfully picks this up as a request to toggle the touchpad status. This works nearly perfectly, except that if the switch is flipped while the laptop is off or asleep, then the toggle state gets out of sync with the switch position, and the switch now has the opposite of the intended effect. KEY_F21 appears to be designed for stateless switches like a hotkey on a keyboard, whereas my laptop's switch has distinct on and off positions.

Does there exist a different pair of keycodes that I could use as "request user space to disable touchpad" and "request user space to enable touchpad" rather than a single "request user space to toggle touchpad"? Failing that, what pair of keycodes would be safe for me to use in the driver that wouldn't have any pre-defined behavior in X or a desktop environment so that I could setup custom shortcuts for them in my DE (Gnome 3.18)?

Some things I already tried that didn't work:

  • Using KEY_F22 and KEY_F23. At first glance, these appear to be touchpad on and off codes. Unfortunately, it turns out that they are not requests for user space to change the touchpad state, but rather notices to user space along the lines of, "the driver or hardware has changed the touchpad state and I'm just letting user space know the new status for the sake of displaying an alert".
  • Looked through the latest kernel version of input-event-codes.h for any other obvious promising codes. The only ones I found were KEY_TOUCHPAD_TOGGLE, KEY_TOUCHPAD_ON, and KEY_TOUCHPAD_OFF (0x212-0x214). I tried these, but none had any effect because the X server cannot receive any keycodes above 247 (0xF7). I need X or the DE to handle the touchpad enable/disable event in user space, so keycodes that high are out.

Your Answer

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

Browse other questions tagged or ask your own question.