Skip to main content

decode_keyboard

Function decode_keyboard 

Source
pub fn decode_keyboard(
    report: &[u8; 8],
    last: &mut [u8; 6],
    rep: &mut KeyRepeat,
    caps: &mut bool,
    now: u64,
    emit: impl FnMut(u8),
    on_unmapped: impl FnMut(u8),
)
Expand description

Decode a keyboard boot report (modifiers in byte 0, up to six keycodes in bytes 2..8) with N-key edge detection: emit(ascii) is called for every key that is down now but was not in last, so rolling onto a new key before releasing the previous one drops nothing and a held key fires exactly once. last is updated to this report’s keycodes for the next call.

rep/now drive typematic auto-repeat: the newest printable key still held is armed (at tick now) so the driver’s KeyRepeat::poll re-emits it while held; releasing it disarms repeat. A key we don’t map is reported via on_unmapped (loud, not silently dropped - §3.12) so its HID usage code can be logged and added. caps is the host’s Caps Lock latch (toggled on each fresh Caps Lock press); the driver owns it per keyboard and passes it in, so the state persists across reports. It cases letters via hid_to_ascii (Caps Lock XORs Shift, letters only).