kitten/key

This module contains a few simple functions to work with keyboard input. These are intended for use inside your update function. The custom Key types ensures that you can only check for real keys and prevents misspellings. Use key.ANY to check if any key was pressed, released or was down during a frame.

Example:

let new_pos = case key.is_down(key.A) {
  True -> pos |> vec2.add(Vec2(1.0, 0.0))
  False -> pos
}

Types

pub type Key {
  ANY
  A
  B
  C
  D
  E
  F
  G
  H
  I
  J
  K
  L
  M
  N
  O
  P
  Q
  R
  S
  T
  U
  V
  W
  X
  Y
  Z
  Space
  ArrowLeft
  ArrowUp
  ArrowRight
  ArrowDown
  Backspace
  Tab
  Enter
  ShiftLeft
  ShiftRight
  ControlLeft
  ControlRight
  AltLeft
  AltRight
  Pause
  CapsLock
  Escape
  PageUp
  PageDown
  End
  Home
  PrintScreen
  Insert
  Delete
  Digit0
  Digit1
  Digit2
  Digit3
  Digit4
  Digit5
  Digit6
  Digit7
  Digit8
  Digit9
  MetaLeft
  MetaRight
  ContextMenu
  Numpad0
  Numpad1
  Numpad2
  Numpad3
  Numpad4
  Numpad5
  Numpad6
  Numpad7
  Numpad8
  Numpad9
  NumpadMultiply
  NumpadAdd
  NumpadSubtract
  NumpadDecimal
  NumpadDivide
  F1
  F2
  F3
  F4
  F5
  F6
  F7
  F8
  F9
  F10
  F11
  F12
  NumLock
  ScrollLock
  AudioVolumeMute
  AudioVolumeDown
  AudioVolumeUp
  LaunchMediaPlayer
  LaunchApplication1
  LaunchApplication2
  Semicolon
  Equal
  Comma
  Minus
  Period
  Slash
  Backquote
  BracketLeft
  Backslash
  BracketRight
  Quote
}

Constructors

  • ANY
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • I
  • J
  • K
  • L
  • M
  • N
  • O
  • P
  • Q
  • R
  • S
  • T
  • U
  • V
  • W
  • X
  • Y
  • Z
  • Space
  • ArrowLeft
  • ArrowUp
  • ArrowRight
  • ArrowDown
  • Backspace
  • Tab
  • Enter
  • ShiftLeft
  • ShiftRight
  • ControlLeft
  • ControlRight
  • AltLeft
  • AltRight
  • Pause
  • CapsLock
  • Escape
  • PageUp
  • PageDown
  • End
  • Home
  • PrintScreen
  • Insert
  • Delete
  • Digit0
  • Digit1
  • Digit2
  • Digit3
  • Digit4
  • Digit5
  • Digit6
  • Digit7
  • Digit8
  • Digit9
  • MetaLeft
  • MetaRight
  • ContextMenu
  • Numpad0
  • Numpad1
  • Numpad2
  • Numpad3
  • Numpad4
  • Numpad5
  • Numpad6
  • Numpad7
  • Numpad8
  • Numpad9
  • NumpadMultiply
  • NumpadAdd
  • NumpadSubtract
  • NumpadDecimal
  • NumpadDivide
  • F1
  • F2
  • F3
  • F4
  • F5
  • F6
  • F7
  • F8
  • F9
  • F10
  • F11
  • F12
  • NumLock
  • ScrollLock
  • AudioVolumeMute
  • AudioVolumeDown
  • AudioVolumeUp
  • LaunchMediaPlayer
  • LaunchApplication1
  • LaunchApplication2
  • Semicolon
  • Equal
  • Comma
  • Minus
  • Period
  • Slash
  • Backquote
  • BracketLeft
  • Backslash
  • BracketRight
  • Quote

Functions

pub fn is_down(key: Key) -> Bool

Returns True if the key was pressed in the time since the last frame, but has not yet been released, and False otherwise.

pub fn was_pressed(key: Key) -> Bool

Returns True if the key was pressed in the time since the last frame, and False otherwise.

pub fn was_released(key: Key) -> Bool

Returns True if the key was released in the time since the last frame, and False otherwise.

Search Document