STRUCT KEY_ENTRY(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct key_entry(9) β€” aka the kernel API manual page you're about to be obsessed with

okay so real talk, this is a page from the Kernel API Manual and it's all about struct key_entry, which is literally the glow-up of keymaps for input devices πŸŽ€


✨ NAME ✨

struct key_entry β€” it's a keymap entry, bestie, made for use in a sparse keymap πŸ¦‹


🌸 SYNOPSIS 🌸

struct key_entry {
    int type;
    u32 code;
    union {
      u16 keycode;
      struct {
        u8 code;
        u8 value;
      } sw;
    };
 };

like… look at her. she's structured. she's union'd. she's everything πŸ’…


🧩 Members 🧩

  • type β€” the type of the key entry, and the squad is KE_KEY, KE_SW, KE_VSW, KE_END. and here's the fun part: drivers are allowed to extend the list with their own private definitions πŸ‘‘ (yes, they get creative license, we love that for them)
  • code β€” device-specific data that identifies the button/switch. so it's like the device's little name-tag for it 🏷️
  • {unnamed_union} β€” anonymous. that's it. that's the whole description. she has no name and she doesn't need one, main character energy fr fr πŸ™ˆ
  • keycode β€” the KEY_* code assigned to a key/button ⭐
  • sw β€” a struct with code/value used by KE_SW and KE_VSW 🫢
  • sw.code β€” the SW_* code assigned to a switch πŸ”₯
  • sw.value β€” the value that should be sent in an input even when a KE_SW switch is toggled. but heads up: KE_VSW switches ignore this field entirely and expect the driver to supply the value for the event. so like, not every switch is gonna read this field, iykyk πŸ’€

πŸ’– Description πŸ’–

so what is this structure? it defines an entry in a sparse keymap, and sparse keymaps are used by some input devices β€” specifically the ones where the traditional table-based approach is just not suitable 😭 like the old way simply doesn't fit them, so they got this instead. it's giving "custom solution because the standard one ate but not for everyone" ✨


🌈 SEE ALSO 🌈

  • Kernel file ./include/linux/input/sparse-keymap.h β€” go read her, she's iconic πŸ“–

ngl, if you're poking at sparse keymaps in the kernel, this struct is your bestie. treat her right 🫢

and that's the whole page, bestie πŸ’– this gem came from ./include/linux/input and she's dated October 2026 β€” periodt, slay, go write some drivers βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from