Keyboard.Event


type alias KeyboardEvent =
{ altKey : Bool
, ctrlKey : Bool
, key : Maybe String
, keyCode : Key
, metaKey : Bool
, repeat : Bool
, shiftKey : Bool
}

The key field may or may not be present, depending on the listener ("keydown" vs. "keypress" vs. "keyup"), browser, and key pressed (character key vs. special key). If not present, it will be Nothing here.

The keyCode is normalized by decodeKeyboardEvent to use whichever of which, keyCode or charCode is provided, and made type-safe via Keyboard.Key.


decodeKeyboardEvent : Decoder KeyboardEvent

Decode a KeyboardEvent from a keyboard event.


considerKeyboardEvent : (KeyboardEvent -> Maybe msg) -> Decoder msg

You provide a function which turns a KeyboardEvent into a message for your update function. You get back a Decoder for those messages.

When your function returns Nothing, the event will not reach your update function. This allows you to filter keyboard events inside the decoder, rather than in the update function. Whether this is a good idea or not depends on your scenario.


decodeKeyCode : Decoder Int

Decode keyCode, which or charCode from a keyboard event to get a numeric code for the key that was pressed.


decodeKey : Decoder (Maybe String)

Decode the key field from a keyboard event.

Results in Nothing if the key field is not present, or blank.