chickadee » hypergiant » make-binding

(make-binding ID KEY [scancode?: SCANCODE?] [mods: MODS] [press: PRESS] [release: RELEASE] [toggle: TOGGLE] [reverse-toggle: REVERSE-TOGGLE])procedure

Create a binding with the identifier ID for the key (or button) KEY. ID may be any sort of object that can be compared with equal?, that should be unique for a collection of bindings. SCANCODE? is a boolean (defaulting to #f) that indicates whether KEY is a scancode or not (a scancode is a system+hardware-specific integer that corresponds to a particular key). MODS is a list of modifiers that must be held at the same time as the KEY for the action to take place, and may be a list containing any or all of +mod-super+, +mod-alt+, +mod-control+, and +mod-shift+. PRESS is a zero element function that is activated on a press event. RELEASE is a zero element function that is activated on a release event. TOGGLE and REVERSE-TOGGLE expect a parameter that must be an integer. TOGGLE indicates that when the key (plus mods) is pressed, the parameter should be incremented, and decremented when released. REVERSE-TOGGLE indicates the opposite. If TOGGLE or REVERSE-TOGGLE are specified, PRESS and RELEASE will be ignored, and only one of TOGGLE or REVERSE-TOGGLE may be used for a binding.

TOGGLE and REVERSE-TOGGLE are useful when two keys are used to perform a continuous action (that may be negated). The game’s update loop should check the parameter passed to the toggle binding to see what action should be performed. For instance, if a parameter move is defined as 0, and set as a toggle when the right key is pressed and reverse-toggle when the left key is pressed, the movement of a character for a given frame can be determined by multiplying (move) by the character’s movement speed.