On this page:
kitty-key
parse-kitty-csi
kitty-key-code->key
kitty-modifier-mask
kitty-event-type
kitty-csi-final?

4 Keyboard parser coverage🔗ℹ

The parser is a pure function over one already-framed CSI sequence; it never reads a port and never changes a parameter.

struct

(struct kitty-key (key mods event-type text shifted base raw))

  key : (or/c char? symbol? #f)
  mods : (list/c boolean? boolean? boolean? boolean? boolean? boolean? boolean? boolean?)
  event-type : (or/c 'press 'repeat 'release)
  text : (or/c string? #f)
  shifted : (or/c char? #f)
  base : (or/c char? #f)
  raw : bytes?
The intermediate representation produced by parse-kitty-csi. mods is (list ctrl? alt? shift? super? hyper? meta? caps-lock? num-lock?), and key is #f for a pure text event. Note that kitty-key-event-type is the event-type accessor of this struct (the name is generated from the field name), while kitty-key-event-event-type is the accessor of kitty-key-event; for events prefer the generic key-event-type.

procedure

(parse-kitty-csi seq) → (or/c kitty-key? #f)

  seq : bytes?
Parses a complete CSI sequence. Returns #f when seq is not a kitty keyboard event, so the caller can fall back to the legacy ANSI parser.

procedure

(kitty-key-code->key code) → (or/c char? symbol? #f)

  code : exact-nonnegative-integer?
Maps a kitty key code to a key-event key: 'escape, 'enter, 'tab, 'backspace, #\space, a char?, a named symbol for the Private Use Area functional keys ('f13–'f24, 'kp-*, 'caps-lock, ...), or an unlisted 'kitty-N symbol. Code 0 (pure text) yields #f.

procedure

(kitty-modifier-mask encoded)

 → (list/c boolean? boolean? boolean? boolean? boolean? boolean? boolean? boolean?)
  encoded : (or/c exact-nonnegative-integer? #f)
Decodes kitty’s encoded modifier value (1 plus a bitmask) into (list ctrl? alt? shift? super? hyper? meta? caps-lock? num-lock?).

procedure

(kitty-event-type n) → (or/c 'press 'repeat 'release)

  n : (or/c exact-nonnegative-integer? #f)
Maps the encoded event type to 'press (1), 'repeat (2) or 'release (3); other values are treated as 'press.

procedure

(kitty-csi-final? b) → boolean?

  b : byte?
True when the byte b is a final byte this parser handles: u, ~, A–F, H, P, Q, S or Z.

The parser handles:

  • CSI unicode-key-code:alternate-key-codes ; modifiers:event-type ; text u

  • CSI number ; modifiers:event-type ~

  • CSI 1 ; modifiers:event-type [ABCDEFHPQS]

  • press / repeat / release and all kitty modifiers

  • alternate shifted key, base layout key and associated text

  • F1–F24, KP keys, CapsLock/ScrollLock/NumLock/Menu/PrintScreen/Pause

  • CSI ? flags u query replies are ignored

  • CSI 1;5R is left to the Cursor Position Report, not treated as F3

Unrecognized sequences fall back to the base ANSI parser, including modifyOtherKeys.