Forked from: https://github.com/ohanhi/keyboard-extra.
NOTE: I haven't upgraded this to Elm 0.19, I don't intend on doing this either, I'm not sure I want to keep this library alive.
A very lightweight library to create hotkeys for apps. Not intended for games.
Javascript has issues with key events
Add it to your Model:
type alias Model =
{ keysDown : Keyboard.Extra.Model
-- ...
}
Add it to your init:
init =
{ keysDown = Keyboard.Extra.init
-- ...
}
-- If your init also expects a Cmd then pair it with Cmd.none.
Add it to your messages:
type Msg =
KeyboardExtraMsg Keyboard.Extra.Msg
-- ...
Add it to your update.
case msg of
KeyboardExtraMsg keyMsg ->
let
newKeysDown =
Keyboard.Extra.update keyMsg model.keysDown
in
-- If you want to react to key-presses, call a function here instead
-- of just updating the model (you should still update the model).
({ model | keysDown = newKeysDown }, Cmd.none)
-- ...
And lastly, hook up your subscriptions:
subscriptions model =
Sub.batch
[ Sub.map KeyboardExtraMsg Keyboard.Extra.subscriptions
-- ...
]