ohanhi/keyboard/2.0.0

NOTE: the latest version is 2.0.1

Keyboard.Arrows

Arrow keys and WASD get special treatment using the functions in this module. This is particularly useful for games.

type alias Arrows =
{ x : Int
, y : 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 down
arrows : List 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 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 }
= North
| NorthEast
| East
| SouthEast
| South
| SouthWest
| West
| NorthWest
| NoDirection

Type representation of the arrows.

Gives the arrow keys' pressed down state as follows:

arrowsDirection []
--> NoDirection


arrowsDirection [ ArrowLeft ]
--> West


arrowsDirection [ ArrowUp, ArrowRight ]
--> NorthEast


arrowsDirection [ ArrowDown, ArrowLeft, ArrowRight ]
--> South

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 : RawKey -> Maybe 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