Reading — step 1 of 5
Read
~1 min readGame Loop
Input Handling
Input sources:
- Keyboard: which keys are pressed/just pressed/released.
- Mouse: position, buttons, wheel.
- Gamepad: thumbsticks (analog), buttons, triggers.
- Touch: positions of fingers.
Input events:
- KeyDown / KeyUp.
- MouseMove / MouseDown / MouseUp / MouseWheel.
- GamepadConnected / Disconnected.
Input state vs events:
- State: "is space pressed right now?" (poll).
- Events: "space was just pressed" (callback or queue).
python
Per frame: reset pressed/released, process new events, then game logic queries.
python
Edge-triggered (pressed) vs level-triggered (down):
- Jump: edge (only on press).
- Move: level (continuous while held).
Input axes (gamepads):
- Thumbstick: -1.0 to 1.0 per axis.
- Deadzone: ignore tiny movements (0.05-0.15 typical).
python
Input mapping:
- Action → key/button.
- "JUMP" → SPACE on keyboard, A button on gamepad.
- Allow rebinding via config.
python
Modern input libs:
- SDL: cross-platform input + window.
- GLFW: similar.
- DirectInput / XInput: Windows-specific.
- SDL3 in development.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…