elm-lang/core/1.1.1

NOTE: this package moved to elm/core

NOTE: this package is not compatible with Elm 0.19.1

Keyboard

Library for working with keyboard input.

Representing Keys

type alias KeyCode =
Int

Type alias to make it clearer what integers are supposed to represent in this library. Use Char.toCode and Char.fromCode to convert key codes to characters. Use the uppercase character with toCode.

Directions

Signal
{ x : Int
, y : Int
}

A signal of records indicating which arrow keys are pressed.

* { 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.

Signal
{ x : Int
, y : Int
}

Just like the arrows signal, but this uses keys w, a, s, and d, which are common controls for many computer games.

KeyCode
-> KeyCode
-> KeyCode
-> KeyCode
-> Signal
{ x : Int
, y : Int
}

Custom key directions to support different locales. The order is up, down, left, right.

Specific Keys

The following signals are True when the particular key is pressed and False otherwise.

enter : Signal Bool
space : Signal Bool
ctrl : Signal Bool
shift : Signal Bool
alt : Signal Bool
meta : Signal Bool

The meta key is the Windows key on Windows and the Command key on Mac.

General Keypresses

isDown : KeyCode -> Signal Bool

Whether an arbitrary key is pressed.

keysDown : Signal (List KeyCode)

List of keys that are currently down.

lastPressed : Signal KeyCode

The latest key that has been pressed.