### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.2 documentation »

# `grease.controls` – Game Controls

Control systems for binding controls to game logic

class `grease.controls.``KeyControls`

  System that maps subclass-defined action methods to keys.

  Keys may be mapped in the subclass definition using decorators defined here as class methods or at runtime using the `bind_key_*` instance methods.

  See an example implementation in the tutorial.

  `bind_key_hold`(method, key, modifiers=0)
    Bind a method to a key at runtime to be invoked when the key is held down, this replaces any existing key hold binding for this key. To unbind the key entirely, pass `None` for method.
  `bind_key_press`(method, key, modifiers=0)
    Bind a method to a key at runtime to be invoked when the key is initially pressed, this replaces any existing key hold binding for this key. To unbind the key entirely, pass `None` for method.
  `bind_key_release`(method, key, modifiers=0)
    Bind a method to a key at runtime to be invoked when the key is releaseed, this replaces any existing key hold binding for this key. To unbind the key entirely, pass `None` for method.
  classmethod `key_hold`(symbol, modifiers=0)
    Decorator to bind a method to be executed where a key is held down
  classmethod `key_press`(symbol, modifiers=0)
    Decorator to bind a method to be executed where a key is initially depressed
  classmethod `key_release`(symbol, modifiers=0)
    Decorator to bind a method to be executed where a key is released
  `on_key_press`(*key)
    Handle pyglet key press. Invoke key press methods and activate key hold functions
  `on_key_release`(*key)
    Handle pyglet key release. Invoke key release methods and deactivate key hold functions
  `step`(dt)
    invoke held key functions
  `world`
    `grease.World` object this system is bound to

### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.2 documentation »