package matrix

  1. Overview
  2. Docs

Module Input.KeymapSource

Key binding maps. See Keymap.

Key binding maps.

A keymap binds key and modifier combinations to values. Later bindings take precedence over earlier ones: add general bindings first, then more specific ones to override.

Modifier semantics

add leaves unspecified modifiers as wildcards (match any state), enabling prefix-free patterns like Ctrl+C without constraining Shift or Alt. add_char defaults all modifiers to false (exact match), so add_char 'c' only matches a plain c press with no modifiers active.

Note. Lock states (caps_lock, num_lock) are not matchable by keymaps since they represent toggle states rather than pressed modifiers.

Keymaps

Sourcetype 'a t

The type for immutable keymaps binding keys to values of type 'a.

Sourceval empty : 'a t

empty is a keymap with no bindings.

Adding bindings

Sourceval add : ?ctrl:bool -> ?alt:bool -> ?shift:bool -> ?super:bool -> ?hyper:bool -> ?meta:bool -> 'a t -> Input__.Event.Key.t -> 'a -> 'a t

add map key data is map with a binding from key to data. Unspecified modifier arguments are wildcards (match any state). Later bindings take precedence.

Sourceval add_char : ?ctrl:bool -> ?alt:bool -> ?shift:bool -> ?super:bool -> ?hyper:bool -> ?meta:bool -> 'a t -> char -> 'a -> 'a t

add_char map c data is like add for the character c. Unlike add, all modifier arguments default to false (exact match).

Finding bindings

Sourceval find : ?event_type:(Input__.Event.Key.event_type -> bool) -> 'a t -> Input__.Event.t -> 'a option

find map event is the most recently added binding matching a Event.Key event with compatible modifiers, or None if event is not a key event or no binding matches.

event_type filters which key event types are eligible. It defaults to accepting Event.Key.Press and Event.Key.Repeat but rejecting Event.Key.Release, which prevents bindings from firing on key-up on terminals supporting the Kitty keyboard protocol. Pass ~event_type:(fun _ -> true) to match all event types.