LWXGL offers two complementary input models that you can use independently or together. The callback model lets you attach a function that LWXGL calls automatically when an event fires — useful for action-based responses like pressing a key to jump or clicking a point to place an object. The polling model lets you query the current state of the mouse and keyboard on demand each frame — ideal for smooth, continuous movement where you need to know whether a key is still held rather than when it was first pressed.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dressedalarm184/lwxgl/llms.txt
Use this file to discover all available pages before exploring further.
Keyboard Callbacks
int:
- For printable ASCII keys, the value is the standard ASCII code (e.g.
'a'= 97,' '= 32). - For special keys, LWXGL maps them to constants defined in
libLWXGL.h:
| Constant | Value | Key |
|---|---|---|
LWXGL_KEY_LEFT | 170 | Left arrow |
LWXGL_KEY_RIGHT | 171 | Right arrow |
LWXGL_KEY_UP | 172 | Up arrow |
LWXGL_KEY_DOWN | 173 | Down arrow |
LWXGL_KEY_FN | 150 | Base value (not a key itself) |
LWXGL_KEY_FN + 1 | 151 | F1 |
LWXGL_KEY_FN + 2 | 152 | F2 |
… | … | … |
LWXGL_KEY_FN + 11 | 161 | F11 |
LWXGL_KEY_FN + N where N is the function-key number. F12 (LWXGL_KEY_FN + 12 = 162) is reserved and will not reach your callback.
GEventAttachKey again replaces the previous callback.
Mouse Click Callbacks
| Parameter | Description |
|---|---|
x, y | Window-relative coordinates of the cursor at the time of release |
btn | X11 button number: 1 = left, 2 = middle, 3 = right |
The click callback is not invoked when a button or checkbox element consumed the click. LWXGL checks elements in ID order on each release event and returns early if a hit is found, so the user callback only fires for clicks on bare window space.
Window Close Callback
GDeleteWindow() is called programmatically). The callback must return:
1— confirm the close;GWindowShouldClose()will return1and the loop will exit.0— cancel the close; the window stays open.
Polling Mouse State
GHandleWindowEvents.
| Output | Description |
|---|---|
*x, *y | Cursor position in window coordinates. Both are -1 when the cursor is outside the window |
*btn | Currently held button number (1/2/3), or 0 if no button is pressed |
Polling Keyboard State
LWXGL tracks up to 8 simultaneously held keys and exposes them through two polling functions.- GQueryKeyDown (single key)
- GQueryKeyboard (all held keys)
1 if the key ch is currently held down, 0 otherwise. ch can be an ASCII value or any of the LWXGL_KEY_* constants. This is the most ergonomic option for per-frame movement logic.Event Dispatch Order
Understanding the order in which LWXGL dispatches events prevents surprises when mixing callbacks with interactive elements:Button and checkbox elements are checked first
On a mouse-button release, LWXGL iterates over all elements in ID order. If the cursor is inside a button or checkbox, that element’s handler fires and the event loop returns early — the user click callback is not called.
User click callback fires for unhandled clicks
Only if no interactive element consumed the click does
GEventAttachClick’s callback receive the event.Input elements consume key events first
On a key press, if the cursor is hovering over a text input element, that input receives the character and the key callback is not called.