STRUCT KEY_ENTRY(9)
π 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 isKE_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β theKEY_*code assigned to a key/button βswβ a struct withcode/valueused byKE_SWandKE_VSWπ«Άsw.codeβ theSW_*code assigned to a switch π₯sw.valueβ the value that should be sent in an input even when aKE_SWswitch is toggled. but heads up:KE_VSWswitches 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms