pyxen.input.keyboard
Access keyboard state and text input.
kbd = pyxen.input.keyboard
Button Model
All keys return a Button object with:
| Property | Type | Description |
|---|---|---|
down | bool | True while held |
pressed | bool | True on the frame the key was pressed |
released | bool | True on the frame the key was released |
value | float | Analog value (usually 1.0 or 0.0) |
Keyboard properties are read-only.
Accessing Keys
Direct Attribute
if kbd.a.pressed:
print("A pressed")
String Indexing
if kbd["space"].down:
print("Jump!")
If a key name is invalid:
kbd["unknown"] # → None
Text Input
text = kbd.text
Returns the text typed this frame (useful for UI input).
Supported Keys
- Letters:
"a"→"z"(case insensitive) - Numbers:
"0"→"9"or"num_0"→"num_9" - Arrows:
"left","right","up","down" - Modifiers:
"left_shift","right_ctrl", etc. - Function keys:
"f1"→"f12" - Symbols:
"minus","equals","comma", etc. - Keypad:
"keypad_0"→"keypad_9"
Example: Movement
if kbd.left.down:
player.x -= 1
if kbd.right.down:
player.x += 1
Notes
- Read-only
- Frame-based state
- Safe to query every update