LWXGL gives you two ways to respond to input. Attach callbacks (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.
GEventAttach*) let the library push events to your code as they occur. Query functions (GQuery*) let you poll the current input state at any point in your frame — useful for smooth continuous movement or when you need input state outside of a callback.
All callbacks are invoked from within GHandleWindowEvents.
Key Constants
LWXGL maps X11 keys that have no printable ASCII value to constants in the range 150–173. These constants are used wherever a key value is expected — in attach callbacks, query results, andGQueryKeyDown.
| Constant | Value | Key |
|---|---|---|
LWXGL_KEY_FN | 150 | Base offset for function keys |
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 + N, where N is the function key number (1–12):
All other keys that have a printable ASCII representation (letters, digits, punctuation, Space, Backspace, etc.) are delivered as their standard ASCII value (e.g.
'a' = 97, Backspace = 8).GEventAttachKey
LWXGL_KEY_* constants for arrows and function keys.
Callback function.
key is:- The ASCII code for printable characters (e.g.
'a','1',' '). LWXGL_KEY_LEFT/LWXGL_KEY_RIGHT/LWXGL_KEY_UP/LWXGL_KEY_DOWNfor arrow keys.LWXGL_KEY_FN + Nfor function keys F1–F12.
- A modal dialog is currently open (
GQueryModalOpen()returns1). - A focused
Inputelement is in the window and the cursor is inside it (the element consumes the key). - A
Consoleelement is focused and under the cursor (Space scrolls the console). - The key combination is Ctrl + Escape (this closes the window before the callback would fire).
F12 is reserved by LWXGL to toggle the debug overlay and is never forwarded to the key callback.
GEventAttachClick
Callback function:
x,y— cursor coordinates relative to the top-left corner of the window at the time of release.btn— X11 button number:1= left,2= middle,3= right. Scroll wheel events (4= up,5= down) are handled internally by Console elements and are never forwarded to this callback.
- A modal dialog is open. The modal’s own click regions handle the event and return early.
- The release lands inside a
Button,Checkbox, orConsoleelement — those elements consume the event.
GEventAttachDelete
WM_DELETE_WINDOW protocol), a call to GDeleteWindow, or Ctrl + Escape. The callback’s return value determines whether the close is allowed.
Callback function. Return
1 to allow the window to close, 0 to block it.GEventAttachDelete is never called, all close events are allowed without restriction.
Example — prompt before closing
GQueryMouse
GHandleWindowEvents as motion and button events arrive — poll this function anywhere in your frame logic to read the latest state.
Receives the cursor’s X coordinate relative to the window origin. Set to
-1 when the cursor is outside the window.Receives the cursor’s Y coordinate relative to the window origin. Set to
-1 when the cursor is outside the window.Receives the currently held button number (
1 = left, 2 = middle, 3 = right). Set to 0 when no button is pressed.GQueryMouse reports the pressed button (i.e. held down), not the most recently released button. For release events, use GEventAttachClick.GQueryKeyboard
LWXGL_KEY_* constant for a key that is currently held down. Slots not occupied by an active key hold 0.
Returns unsigned char* pointing to an array of 8 unsigned char values. This pointer is valid for the lifetime of the window; do not free it.
Example
GQueryKeyDown
GQueryKeyboard exposes.
The key value to test: an ASCII code or a
LWXGL_KEY_* constant.1 if the key is currently held, 0 otherwise.
GQueryKeyDown is the most ergonomic way to test a single key. Use GQueryKeyboard only when you need to inspect all held keys simultaneously.