Convenience helpers for working with keyboard inputs.
Using Keyboard.Extra this way, you get all the help it can provide. You should not use this together with the plain subscriptions.
The message type Keyboard.Extra uses.
You will need to add this to your program's subscriptions.
Use this to initialize the component.
You need to call this (or updateWithKeyChange) to have the set of pressed
down keys update. If you need to know exactly what changed just now, have a look
at the updateWithKeyChange.
The second value updateWithKeyChange may return, representing the actual
change that happened during the update.
This alternate update function answers the question: "Did the pressed down keys in fact change just now?"
You might be wondering why this is a Maybe KeyChange – it's because
keydown events happen many times per second when you hold down a key. Thus,
not all incoming messages actually cause a change in the model.
Note This is provided for convenience, and may not perform well in real
programs. If you are experiencing slowness or jittering when using
updateWithKeyChange, see if the regular update makes it go away.
Check the pressed down state of any Key.
Get the full list of keys that are currently pressed down.
The newest key to go down is the first in the list and so on.
Gives the arrow keys' pressed down state as follows:
{ x = 0, y = 0 } when pressing no arrows.{ x =-1, y = 0 } when pressing the left arrow.{ x = 1, y = 1 } when pressing the up and right arrows.{ x = 0, y =-1 } when pressing the down, left, and right arrows (left and right cancel out).Similar to arrows, gives the W, A, S and D keys' pressed down state.
{ x = 0, y = 0 } when pressing none of W, A, S and D.{ x =-1, y = 0 } when pressing A.{ x = 1, y = 1 } when pressing W and D.{ x = 0, y =-1 } when pressing A, S and D (A and D cancel out).Type representation of the arrows.
Gives the arrow keys' pressed down state as follows:
None when pressing no arrows.West when pressing the left arrow.NorthEast when pressing the up and right arrows.South when pressing the down, left, and right arrows (left and right cancel out).Similar to arrows, gives the W, A, S and D keys' pressed down state.
None when pressing none of W, A, S and D.West when pressing A.NorthEast when pressing W and D.South when pressing A, S and D (A and D cancel out).If you prefer to only get "the facts" and do your own handling, use these subscriptions. Otherwise, you may be more comfortable with the Intelligent Helper.
Subscription for key down events.
Note When the user presses and holds a key, there will be many of these messages before the corresponding key up message.
Subscription for key up events.
A Json.Decoder for grabbing event.keyCode and turning it into a Key
import Json.Decode as Json
onKey : (Key -> msg) -> Attribute msg
onKey tagger =
on "keydown" (Json.map tagger targetKey)These are all the keys that have names in Keyboard.Extra.
Convert a key code into a Key.
Convert a Key into a key code.
The internal representation of
Keyboard.Extra. Useful for type annotation.