Represents a physical key. Note that this is not the same as which character is produced by a key (or combination of keys). This is a very important distinction to make to ensure that controls still work as intended no matter what keyboard layout the user is using.
For example, in a game where the player moves the character around with the W
, A
, S
, and D
keys, you'd want the controls to work no matter what keyboard layout the player is using. On a qwerty keyboard, these keys produce the characters 'w', 'a', 's', and 'd', but on a dvorak keyboard, these keys produce the characters ',', 'a', 'o', and 'e'. Therefore, binding the controls to the characters produced by the keys instead of the physical keys themselves would make the controls effectively unusable for a player using a dvorak keyboard (or any other keyboard, for that matter).
Represents a key.
Note that keys that don't have a dedicated constructor can still be used by using the Other
constructor, as long as you know what string event.code
produces.
fromString : String -> Key
Converts a string to a key.
decoder : Json.Decode.Decoder Key
Decodes which key triggered an event.