Dom_html.Keyboard_code
Use Keyboard_code
when you want to identify a key that the user pressed. This should be invoked for keydown and keyup events, not keypress events.
If the browser supports the standardized key
and code
properties, then of_event
on a keypress event will have the correct behavior. Otherwise, it might not identify or might mis-identify which key was pressed. This occurs because the keypress event is designed for printable characters while keydown and keyup are designed for physical keys. Thus, the older properties of keyEvent
change behavior between keydown and keypress events. This change in behavior is what causes the mapping to be incorrect.
type t =
val of_event : keyboardEvent Js.t -> t
val of_key_code : int -> t