Module Note_brr_kit.Key

User keyboard.

Physical keys

Note. Physical keys are for using the keyboard as a controller. Do not use them to derive text input, they are unrelated to the user's keyboard layout for text entry. Use input events for text entry.

type code = int

The type for physical key codes.

type t = [
  1. | `Alt of [ `Left | `Right ]
  2. | `Arrow of [ `Up | `Down | `Left | `Right ]
  3. | `Ascii of Stdlib.Char.t
  4. | `Backspace
  5. | `Ctrl of [ `Left | `Right ]
  6. | `End
  7. | `Enter
  8. | `Escape
  9. | `Func of int
  10. | `Home
  11. | `Insert
  12. | `Key of code
  13. | `Meta of [ `Left | `Right ]
  14. | `Page of [ `Up | `Down ]
  15. | `Return
  16. | `Shift of [ `Left | `Right ]
  17. | `Spacebar
  18. | `Tab
]

The type for physical keys.

Warning. This type is overdefined for now. For example except for `Shift, `Ctrl and Alt, `Left and `Right modifiers cannot be distinguished; `Left is always returned. `Enter and `Return cannot be distinguished, `Return is always returned.

val of_ev : Brr.Ev.Keyboard.t Brr.Ev.t -> t

of_ev e is the physical key of the keyboard event e.

val equal : t -> t -> bool

equal k0 k1 is true iff k0 and k1 are equal.

val compare : t -> t -> int

compare is a total order on keys compatible with equal.

val to_jstr : t -> Jstr.t

Keyboard events

type events

The type for gathering keyboard events on a given target.

val on_target : ?capture:bool -> ?propagate:bool -> ?default:bool -> Brr.Ev.target -> events

on_target t is keyboard events for target t. The other parameters are those of Brr_note.Evr.on_target.

val on_el : ?capture:bool -> ?propagate:bool -> ?default:bool -> Brr.El.t -> events

on_el e is like on_target but for an element.

Key events

val any_down : events -> t Note.event

any_down evs occurs whenever a key goes down on the target.

val any_up : events -> t Note.event

any_down evs occurs whenever a key goes up on the target.

val any_holds : events -> bool Note.signal

any_holds evs is true whenever any key is down.

val down : events -> t -> unit Note.event

down evs k occurs whenever key k goes down on the target.

val up : events -> t -> unit Note.event

up evs k occurs whenever key k goes up on the target.

val holds : events -> t -> bool Note.signal

holds evs k is true whenever k is held down on the target.

Modifiers signals

val alt : events -> bool Note.signal

alt evs is true whenver an alt key is down on the target. Equivalent to:

S.Bool.(holds evs (`Alt `Left) || holds evs (`Alt `Right))
val ctrl : events -> bool Note.signal

ctrl evs is true whenver an ctrl key is down on the target. Equivalent to:

S.Bool.(holds evs (`Ctrl `Left) || holds evs (`Ctrl `Right))
val meta : events -> bool Note.signal

meta evs is true whenver an meta key is down on the target. Equivalent to:

S.Bool.(holds evs (`Meta `Left) || holds evs (`Meta `Right))
val shift : events -> bool Note.signal

shift evs is true whenver an shift key is down on the target. Equivalent to:

S.Bool.(holds evs (`Meta `Left) || holds evs (`Meta `Right))

Semantic incoherences

holds and any_holds may be initially set to false even though they should be true if on_target is invoked when the corresponding keys are depressed.

Key repeat events

Key repeat events are not exposed. There are two main use cases for key repeat. First during text input, but his should be handled by text input events and is out of scope. Second for controlling changes to a variable over time, e.g. scrolling with a keyboard. In the latter case it is better to create a timing signal or event with a known rate while the key is held.