ohanhi/keyboard-extra/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Keyboard.Extra

Convenience helpers for working with keyboard inputs.

Model

type alias Model =
{ keysDown : Set KeyCode }

The set of keys that are currently pressed down.

Keyboard key

type Key
= Cancel
| Help
| BackSpace
| Tab
| Clear
| Enter
| Shift
| Control
| Alt
| Pause
| CapsLock
| Escape
| Convert
| NonConvert
| Accept
| ModeChange
| Space
| PageUp
| PageDown
| End
| Home
| ArrowLeft
| ArrowUp
| ArrowRight
| ArrowDown
| Select
| Print
| Execute
| PrintScreen
| Insert
| Delete
| Number0
| Number1
| Number2
| Number3
| Number4
| Number5
| Number6
| Number7
| Number8
| Number9
| Colon
| Semicolon
| LessThan
| Equals
| GreaterThan
| QuestionMark
| At
| CharA
| CharB
| CharC
| CharD
| CharE
| CharF
| CharG
| CharH
| CharI
| CharJ
| CharK
| CharL
| CharM
| CharN
| CharO
| CharP
| CharQ
| CharR
| CharS
| CharT
| CharU
| CharV
| CharW
| CharX
| CharY
| CharZ
| Super
| ContextMenu
| Sleep
| Numpad0
| Numpad1
| Numpad2
| Numpad3
| Numpad4
| Numpad5
| Numpad6
| Numpad7
| Numpad8
| Numpad9
| Multiply
| Add
| Separator
| Subtract
| Decimal
| Divide
| F1
| F2
| F3
| F4
| F5
| F6
| F7
| F8
| F9
| F10
| F11
| F12
| F13
| F14
| F15
| F16
| F17
| F18
| F19
| F20
| F21
| F22
| F23
| F24
| NumLock
| ScrollLock
| Circumflex
| Exclamation
| DoubleQuote
| Hash
| Dollar
| Percent
| Ampersand
| Underscore
| OpenParen
| CloseParen
| Asterisk
| Plus
| Pipe
| HyphenMinus
| OpenCurlyBracket
| CloseCurlyBracket
| Tilde
| VolumeMute
| VolumeDown
| VolumeUp
| Comma
| Minus
| Period
| Slash
| BackQuote
| OpenBracket
| BackSlash
| CloseBracket
| Quote
| Meta
| Altgr
| Other

These are all the keys that have names in Keyboard.Extra.

Helpers

isPressed : Key -> Model -> Bool

Check the pressed down state of any Key.

arrows : Model -> Arrows

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.
wasd : Model -> Arrows

Similar to arrows, gives the W, A, S and D keys' pressed down state.

pressedDown : Model -> List Key

Get the full list of keys that are currently pressed down.

Wiring

type Msg
subscriptions : Sub Msg

You will need to add this to your program's subscriptions. Otherwise Keyboard.Extra won't be able to provide any information.

init : ( Model, Cmd Msg )
update : Msg -> Model -> ( Model, Cmd Msg )

You need to call this to have the model update.