Module Stk.Key

Utils for managing keys.

val key_is_mod : Tsdl.Sdl.keymod -> bool

key_is_mod k returns whether k is a modifier.

type keystate = {
  1. key : Tsdl.Sdl.keycode;
  2. mask : Tsdl.Sdl.keymod;
  3. mods : Tsdl.Sdl.keymod;
  4. pred : Tsdl.Sdl.keymod -> bool;
}

A keyboard state corresponds to a key state if the specified key is pressed and the active modifiers after applying mask are equal to mods. mods is not used directly but instead a predicate is built to handle modifiers having left and right variants. mods is kept only for printing or storing purpose. mask is used to keep only modifiers of interest. For example not containing Sdl.Kmod.caps results in ignoring the state of Caps Lock when testing. Modifiers with left and right variants are not concerned by the mask since they are handled in the predicate.

val compare_keystate : keystate -> keystate -> int
val keystate_equal : keystate -> keystate -> bool
val pp_keystate : Stdlib.Format.formatter -> keystate -> unit
val set_default_keymask : Tsdl.Sdl.keymod -> unit

Set default mask used by keystate if no mask is specified in argument. Default is Tsdl.Sdl.Kmod.none. Sdl.Kmod.(reserved+mode).

val default_keymask : unit -> Tsdl.Sdl.keymod
val set_default_keymods : Tsdl.Sdl.keymod -> unit

Set default modifiers used by keystate if no modifier is specified in argument. Default is Sdl.Kmod.(reserved+mode).

val default_keymods : unit -> Tsdl.Sdl.keymod
val keystate : ?mask:Tsdl.Sdl.keymod -> ?mods:Tsdl.Sdl.keymod -> Tsdl.Sdl.keycode -> keystate

Create a keystate from the given key. Optional parameters are:

  • mask to set the modifiers whose state will be ignored. If not specified, default_keymask is used.
  • mods to set the required modifiers. If not specified, default_keymods is used.
val match_keys : keystate -> key:Tsdl.Sdl.keycode -> kmod:Tsdl.Sdl.keymod -> bool

match_keys keystate ~key ~kmod returns true if the given key and modifier kmod maths the given keystate.

val keystate_of_string : string -> keystate
val string_of_mods : Tsdl.Sdl.keymod -> string
val string_of_keystate : keystate -> string
val keystate_ocf_wrapper : keystate Ocf.Wrapper.t
val keystate_list_ocf_wrapper : keystate list Ocf.Wrapper.t
val keystate_list_of_string : string -> keystate list
val string_of_keystate_list : keystate list -> string
val is_mod_pressed : Tsdl.Sdl.keymod -> bool
val shift_pressed : unit -> bool
val ctrl_pressed : unit -> bool