pyglet.window.key
Key constants and utilities for pyglet.window.
Usage:
from pyglet.window import Window
from pyglet.window import key
window = Window()
@window.event
def on_key_press(symbol, modifiers):
# Symbolic names:
if symbol == key.RETURN:
# Alphabet keys:
elif symbol == key.Z:
# Number keys:
elif symbol == key._1:
# Number keypad keys:
elif symbol == key.NUM_1:
# Modifiers:
if modifiers & key.MOD_CTRL:
- class KeyStateHandler
Simple handler that tracks the state of keys on the keyboard.
If a key is pressed then this handler holds a
True
value for it. If the window loses focus, all keys will be reset toFalse
to avoid a “sticky” key state.For example:
>>> win = window.Window >>> keyboard = key.KeyStateHandler() >>> win.push_handlers(keyboard) # Hold down the "up" arrow... >>> keyboard[key.UP] True >>> keyboard[key.DOWN] False
- modifiers_string(modifiers: int) str
Return a string describing a set of modifiers.
Example:
>>> modifiers_string(MOD_SHIFT | MOD_CTRL) 'MOD_SHIFT|MOD_CTRL'
- motion_string(motion: int) str
Return a string describing a text motion from a motion constant.
Example:
>>> motion_string(MOTION_NEXT_WORD) 'MOTION_NEXT_WORD'
- Return type:
- symbol_string(symbol: int) str
Return a string describing a key symbol from a key constant.
Example:
>>> symbol_string(BACKSPACE) 'BACKSPACE'
- Return type:
- user_key(scancode: int) int
Return a key symbol for a key not supported by pyglet.
This can be used to map virtual keys or scancodes from unsupported keyboard layouts into a machine-specific symbol. The symbol will be meaningless on any other machine, or under a different keyboard layout.
Applications should use user-keys only when user explicitly binds them (for example, mapping keys to actions in a game options screen).
- Return type:
Key Constants
Modifier mask constants
|
|
|
|
|
|
|
|
|
|
|
ASCII commands
|
|
|
|
|
|
|
|
|
|
|
Cursor control and motion
|
|
|
|
|
|
|
|
|
Misc functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Text motion constants
These are allowed to clash with key constants because they abstract common text motions from their platform-specific keyboard shortcuts. See Motion events for more information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Number pad
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function keys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Modifiers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Latin-1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|