module Key:sig
..end
Consult information about getting keyboard events and
limitations.
val event_target : unit -> Dom_html.eventTarget Js.t option
source ()
is the event target used for keyboard events.val set_event_target : Dom_html.eventTarget Js.t option -> unit
set_event_target target
sets the event target to target. If None
the canvas of the surface will be used.
Warning. This may be removed in the future.
Important. You need to set the event target before
calling Useri.App.init
. And a Useri.App.release
sets
the event target back to None
.
val key_capture : unit -> Useri_base.Key.id -> bool
key_capture ()
is the function that determines whether key
events related to a key are captured by Useri (i.e prevent
default action and stop propagation). The initial function never
captures.val set_key_capture : (Useri_base.Key.id -> bool) -> unit
There are a few things you need to make sure are setup in order to get the keyboard events.
First to get events directly on the HTML canvas associated to the
surface it needs to have a tabindex
attribute. If Useri
creates the canvas it sets one, but don't forget to set one if you
provide the canvas at initialization time through an
handle. Events will only be generated
once the user has focused the canvas in one way or another
(e.g. by clicking on it). The latter operation may introduce a
selection box around the canvas, the selection box can be hidden
by applying the CSS rule { outline: none; }
on the canvas.
You can also choose to get the keyboard events from another event
target using the Useri_jsoo.Key.set_event_target
before initializing the
application. For example using the Dom_html.window
will prevent
the user from having to focus in order for you to get keyboard
events.
By default keyboard event will not stop propagating and will perform
their default action. You can prevent that to occur on certain keys
by registering a function with Useri_jsoo.Key.set_key_capture
. Note that
in certain browsers (e.g. Safari) it is not possible to prevent
the default action of certain key strokes.
Fullscreen. Note that in general in fullscreen mode you may not get keyboard events or only some of them for security reasons.
The following limitations exist (they may be lifted in the future).
`Enter
and
`Return
keys. `Return
is always returned.`Left
and `Right
keys for
modifiers `Alt, `Ctrl, `Meta
and `Shift
. It is advised to use
handless Useri.Key.alt
, Useri.Key.ctrl
, Useri.Key.meta
and
Useri.Key.shift
for detecting modifiers.