Arrow keys and WASD get special treatment using the functions in this module. This is particularly useful for games.
{ x : Basics.Int, y : Basics.Int }
Record type used for arrows
and wasd
.
Both x
and y
can range from -1
to 1
, and are 0
if no keys are pressed.
For example:
{ x = 1, y = 0 }
means to the right{ x = 0, y = -1 }
means downarrows : List Keyboard.Key -> Arrows
Gives the arrow keys' pressed down state as follows:
arrows [] --> { x = 0, y = 0 }
arrows [ ArrowLeft ] --> { x = -1, y = 0 }
arrows [ ArrowUp, ArrowRight ] --> { x = 1, y = 1 }
arrows [ ArrowDown, ArrowLeft, ArrowRight ]
--> { x = 0, y = -1 }
wasd : List Keyboard.Key -> Arrows
Similar to arrows
, gives the W, A, S and D keys' pressed down state.
wasd []
--> { x = 0, y = 0 }
wasd [ Character "A" ]
--> { x = -1, y = 0 }
wasd [ Character "W", Character "D" ]
--> { x = 1, y = 1 }
wasd [ Character "A", Character "S", Character "D" ]
--> { x = 0, y = -1 }
Type representation of the arrows.
arrowsDirection : List Keyboard.Key -> Direction
Gives the arrow keys' pressed down state as follows:
arrowsDirection []
--> NoDirection
arrowsDirection [ ArrowLeft ]
--> West
arrowsDirection [ ArrowUp, ArrowRight ]
--> NorthEast
arrowsDirection [ ArrowDown, ArrowLeft, ArrowRight ]
--> South
wasdDirection : List Keyboard.Key -> Direction
Similar to arrows
, gives the W, A, S and D keys' pressed down state.
wasdDirection []
--> NoDirection
wasdDirection [ Character "A" ]
--> West
wasdDirection [ Character "W", Character "D" ]
--> NorthEast
wasdDirection [ Character "A", Character "S", Character "D" ]
--> South
arrowKey : Keyboard.RawKey -> Maybe Keyboard.Key
A key parser for just the Arrow keys and W, A, S, D. They are always uppercase.
[ArrowLeft] -> Just ArrowLeft
[A] -> Character "A"
[B] -> Nothing