Next: , Up: Input   [Contents][Index]


4.4.1 Keyboard

(use-modules (sly input keyboard))

Keyboard hooks, signals, and procedures.

Scheme Variable: key-press-hook

This hook is run whenever a key is pressed down. Procedures added to this hook should accept two arguments: key, a symbol, and char, a unicode character.

Scheme Variable: key-release-hook

This hook is run whenever a key is released. Procedures added to this hook should accept two arguments: key, a symbol, and char, a unicode character.

Scheme Signal: key-last-down

The last key pressed.

Scheme Signal: key-last-up

The last key released.

Scheme Procedure: key-down? key

Create a signal for the state of key. The signal value is #t when key is pressed and #f otherwise.

A lot of games use directional keys to control the player. The below procedure and signals make this style of movement easy to use.

Scheme Procedure: key-directions up down left right

Create a signal whose value is a 2D unit vector that can be used for 8-directional movement. The vector is determined by the state of the directional keys: up, down, left, right.

Scheme Signal: key-arrows

A 2D directional vector based on the state of the arrow keys.

Scheme Signal: key-wasd

A 2D directional vector based on the state of the WASD keys.