-
Notifications
You must be signed in to change notification settings - Fork 0
04 input
Copyright (c) 2024-2026 Jack Waechter. MIT licensed.
Input is sampled after AP_PumpEvents(). Each call is “this frame” relative to the last pump.
if (AP_IsKeyPressed(AP_KEY_ESCAPE)) {
AP_RequestClose();
}
if (AP_IsKeyDown(AP_KEY_W)) {
y -= speed * dt;
}
if (AP_IsKeyReleased(AP_KEY_SPACE)) {
/* just let go */
}| Query | Meaning |
|---|---|
AP_IsKeyDown |
Held |
AP_IsKeyPressed |
Went down this frame |
AP_IsKeyReleased |
Went up this frame |
AP_IsKeyRepeat |
OS key-repeat |
Modifiers: AP_IsShiftDown(), AP_IsCtrlDown(), AP_IsAltDown().
Key names match GLFW (AP_KEY_A … AP_KEY_Z, AP_KEY_LEFT, AP_KEY_SPACE, function keys).
Coordinates are window pixels, top-left origin.
float mx = (float)AP_GetMouseX();
float my = (float)AP_GetMouseY();
if (AP_IsMousePressed(AP_MOUSE_LEFT)) {
/* click */
}
if (AP_IsMouseDown(AP_MOUSE_RIGHT)) {
/* drag */
}AP_GetMouseDeltaX() / AP_GetMouseDeltaY() are motion since last pump. Useful for look / camera.
If you are using the immediate GUI, skip game clicks when the UI wants the pointer:
if (!AP_GuiWantCaptureMouse() && AP_IsMousePressed(AP_MOUSE_LEFT)) {
/* world click */
}Indices are 0 .. AP_GAMEPAD_MAX-1. Stick Y is up = negative, same as GLFW.
int pad = AP_GetFirstGamepad();
if (pad >= 0 && AP_IsGamepadConnected(pad)) {
AP_Vec2 stick = AP_GetGamepadStick(pad, AP_GAMEPAD_STICK_LEFT);
x += stick.x * speed * dt;
y += stick.y * speed * dt; /* up is negative */
if (AP_IsGamepadButtonPressed(pad, AP_GAMEPAD_A)) {
jump = true;
}
float trigger = AP_GetGamepadTrigger(pad, AP_GAMEPAD_AXIS_RIGHT_TRIGGER);
}AP_SetGamepadDeadzone(0.15f) if the stick chatters at rest.
AP_Tick() is pygame's Clock.tick: it waits so the frame hits AP_SetTargetFPS, then returns delta time in seconds. 0 means uncapped.
AP_SetTargetFPS(60);
while (AP_IsRunning()) {
AP_PumpEvents();
double dt = AP_Tick(); /* or AP_GetDeltaTime() after Tick */
AP_SpriteUpdate(&walk, (float)dt);
}AP_TickFPS(60) is the one-liner. AP_GetFPS() is a smoothed measurement, not the cap. Hitch frames are clamped to 0.1s.
AP2 — Application Primitives. MIT licensed. Copyright (c) 2024-2026 Jack Waechter. Generated from docs/ in the repository.
- Home
- Guides
- Tutorials
- Tutorial 01 — Hello window
- Tutorial 02 — Drawing in 2D
- Tutorial 03 — Textures and sprites
- Tutorial 04 — Input
- Tutorial 05 — Audio
- Tutorial 06 — Text and fonts
- Tutorial 07 — Immediate GUI
- Tutorial 08 — 3D
- Tutorial 09 — Shaders and post-processing
- Tutorial 10 — Breakout
- Tutorial 11 — Top-down walker
- Tutorial 12 — Desktop tool
- Tutorial 13 — Tilemaps
- Tutorial 14 — Advanced 3D: A PBR Product Scene
- Tutorial 15 — Advanced GUI: A Retained-Mode Desktop App
- Tutorial 16 — Camera Rigs and Cinematic Post-Processing
- Tutorial 17 — Capstone: A Complete Application