LWXGL provides two complementary approaches to handling user input. The callback model lets you register functions that are invoked automatically when a key is pressed, the mouse is clicked, or the window close button is activated. The polling model lets you query the current state of the mouse and keyboard at any time — useful inside per-frame logic driven byDocumentation 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.
GSimpleWindowLoop. Both approaches can be used together in the same application.
GEventAttachKey
LWXGL_KEY_* constants defined below.
Pointer to the callback function. The
key parameter delivered to the callback is the ASCII value of the pressed character, or an LWXGL_KEY_* constant for non-printable keys.When an input element is hovered and the user types, keystrokes are consumed by that element and are not forwarded to the key callback. The callback only fires when no focused input element claims the event.
GEventAttachClick
Pointer to the callback function. The parameters delivered to the callback are:
x— cursor X position at release time (pixels from left edge).y— cursor Y position at release time (pixels from top edge).btn— X11 button number:1= left,2= middle,3= right.
The click callback is not called when a button or checkbox element is clicked — those elements consume the release event before the global callback is reached. It is also suppressed entirely while a modal dialog is open.
GEventAttachDelete
Pointer to the callback function. Return
1 to confirm the close (sets the closing flag), or 0 to cancel it (the window remains open).GQueryMouse
NULL for any of them is undefined behavior.
Receives the current cursor X position in pixels from the left edge of the window. Set to
-1 when the cursor is outside the window.Receives the current cursor Y position in pixels from the top edge of the window. Set to
-1 when the cursor is outside the window.Receives the currently held mouse button (
1 = left, 2 = middle, 3 = right). Set to 0 when no button is held.Both
x and y are set to -1 together whenever the pointer leaves the window area (tracked via X11’s LeaveNotify event). Check for -1 before using these values for hit-testing.GQueryKeyboard
unsigned char[8] array of currently held key codes. Each non-zero slot contains the ASCII value or LWXGL_KEY_* constant of a key being held at the time of the call. Slots whose value is 0 are empty.
Return value — Pointer to the internal 8-element unsigned char array. Do not free or cache this pointer across frames; read it immediately after the call.
GQueryKeyDown
GQueryKeyboard. Scans the 8-element key array and returns whether the specified key is currently held.
The key code to test — either an ASCII character value or an
LWXGL_KEY_* constant.1 if the key is currently held, 0 otherwise.
Special Key Constants
LWXGL translates non-printable keys into numeric constants in the range 150–173, safely above the printable ASCII range (32–126). Use these constants withGQueryKeyDown, or compare against the key parameter inside a GEventAttachKey callback.
| Constant | Value | Key |
|---|---|---|
LWXGL_KEY_FN | 150 | F-key base constant (not a key itself) |
LWXGL_KEY_LEFT | 170 | Left arrow |
LWXGL_KEY_RIGHT | 171 | Right arrow |
LWXGL_KEY_UP | 172 | Up arrow |
LWXGL_KEY_DOWN | 173 | Down arrow |
Function keys are computed as
LWXGL_KEY_FN + n, where n is the function key number (1–12). The resulting values are F1 = 151, F2 = 152, …, F11 = 161, F12 = 162. F12 (value 162) is reserved for the debug overlay toggle and will never appear in a key callback or the keyboard state array.Code Example
The example below shows both the callback and polling approaches used together: a click callback logs where the user clicked, and a per-frame callback usesGQueryKeyDown to move a hypothetical object with the arrow keys.