Banjo API 0.0.1
Multi-purpose C99 API
|
Handle input events such as keyboard, mouse and focus. More...
The event system provides a simple callback interface for handling user interactions with windows, including cursor movement, button presses, keyboard input, and window enter/leave detection.
Events are dispatched via polling with bj_dispatch_events.
Data Structures | |
struct | bj_enter_event_t |
Represent a mouse enter or leave event. More... | |
struct | bj_cursor_event_t |
Represent a mouse cursor movement event. More... | |
struct | bj_button_event_t |
Represent a mouse button event. More... | |
struct | bj_key_event_t |
Represent a keyboard key event. More... | |
struct | bj_event_t |
Represent a generic window-related event. More... | |
union | bj_event_t.__unnamed0__ |
Macros | |
#define | BJ_BUTTON_1 1 |
First button. | |
#define | BJ_BUTTON_2 2 |
Second button. | |
#define | BJ_BUTTON_3 3 |
Third button. | |
#define | BJ_BUTTON_4 4 |
Fourth button. | |
#define | BJ_BUTTON_5 5 |
Fifth button. | |
#define | BJ_BUTTON_LEFT BJ_BUTTON_1 |
Left mouse button. | |
#define | BJ_BUTTON_RIGHT BJ_BUTTON_3 |
Right mouse button. | |
#define | BJ_BUTTON_MIDDLE BJ_BUTTON_2 |
Middle mouse button. | |
#define | BJ_BUTTON_UP BJ_BUTTON_4 |
Scroll up mouse button. | |
#define | BJ_BUTTON_DOWN BJ_BUTTON_5 |
Scroll down mouse button. | |
#define | BJ_KEY_APOSTROPHE BJ_KEY_OEM_7 |
Alias for BJ_KEY_OEM_7. | |
#define | BJ_KEY_BACKSLASH BJ_KEY_OEM_5 |
Alias for BJ_KEY_OEM_5. | |
#define | BJ_KEY_BACKSPACE BJ_KEY_BACK |
Alias for BJ_KEY_BACK. | |
#define | BJ_KEY_CAPSLOCK BJ_KEY_CAPITAL |
Alias for BJ_KEY_CAPITAL. | |
#define | BJ_KEY_COMMA BJ_KEY_OEM_COMMA |
Alias for BJ_KEY_OEM_COMMA. | |
#define | BJ_KEY_ENTER BJ_KEY_RETURN |
Alias for BJ_KEY_RETURN. | |
#define | BJ_KEY_GRAVE_ACCENT BJ_KEY_OEM_3 |
Alias for BJ_KEY_OEM_3. | |
#define | BJ_KEY_HANGUL BJ_KEY_KANA |
Alias for BJ_KEY_KANA. | |
#define | BJ_KEY_HANJA BJ_KEY_KANJI |
Alias for BJ_KEY_KANJI. | |
#define | BJ_KEY_LEFT_ALT BJ_KEY_LMENU |
Alias for BJ_KEY_LMENU. | |
#define | BJ_KEY_LEFT_BRACKET BJ_KEY_OEM_4 |
Alias for BJ_KEY_OEM_4. | |
#define | BJ_KEY_LEFT_CONTROL BJ_KEY_LCONTROL |
Alias for BJ_KEY_LCONTROL. | |
#define | BJ_KEY_LEFT_OS BJ_KEY_LWIN |
Alias for BJ_KEY_LWIN. | |
#define | BJ_KEY_LEFT_SHIT BJ_KEY_LSHIFT |
Alias for BJ_KEY_LSHIFT. | |
#define | BJ_KEY_MINUS BJ_KEY_OEM_MINUS |
Alias for BJ_KEY_OEM_MINUS. | |
#define | BJ_KEY_PAGE_DOWN BJ_KEY_NEXT |
Alias for BJ_KEY_NEXT. | |
#define | BJ_KEY_PAGE_UP BJ_KEY_PRIOR |
Alias for BJ_KEY_PRIOR. | |
#define | BJ_KEY_PERIOD BJ_KEY_OEM_PERIOD |
Alias for BJ_KEY_OEM_PERIOD. | |
#define | BJ_KEY_PLUS BJ_KEY_OEM_PLUS |
Alias for BJ_KEY_OEM_PLUS. | |
#define | BJ_KEY_PRINT_SCREEN BJ_KEY_SNAPSHOT |
Alias for BJ_KEY_SNAPSHOT. | |
#define | BJ_KEY_RIGHT_ALT BJ_KEY_RMENU |
Alias for BJ_KEY_RMENU. | |
#define | BJ_KEY_RIGHT_BRACKET BJ_KEY_OEM_6 |
Alias for BJ_KEY_OEM_6. | |
#define | BJ_KEY_RIGHT_CONTROL BJ_KEY_RCONTROL |
Alias for BJ_KEY_RCONTROL. | |
#define | BJ_KEY_RIGHT_OS BJ_KEY_RWIN |
Alias for BJ_KEY_RWIN. | |
#define | BJ_KEY_RIGHT_SHIFT BJ_KEY_RSHIFT |
Alias for BJ_KEY_RSHIFT. | |
#define | BJ_KEY_SEMICOLON BJ_KEY_OEM_1 |
Alias for BJ_KEY_OEM_1. | |
#define | BJ_KEY_SLASH BJ_KEY_OEM_2 |
Alias for BJ_KEY_OEM_2. | |
Typedefs | |
typedef enum bj_key_t | bj_key |
List of possible keys on a keyboard. | |
typedef enum bj_event_action_t | bj_event_action |
Define event action types for keys or mouse buttons. | |
typedef struct bj_enter_event_t | bj_enter_event |
Represent a mouse enter or leave event. | |
typedef struct bj_cursor_event_t | bj_cursor_event |
Represent a mouse cursor movement event. | |
typedef struct bj_button_event_t | bj_button_event |
Represent a mouse button event. | |
typedef struct bj_key_event_t | bj_key_event |
Represent a keyboard key event. | |
typedef enum bj_event_type_t | bj_event_type |
Identify the type of a generic event. | |
typedef struct bj_event_t | bj_event |
Represent a generic window-related event. | |
typedef void(* | bj_enter_callback_fn_t) (bj_window *, const bj_enter_event *, void *) |
Define the callback type for enter events. | |
typedef void(* | bj_cursor_callback_fn_t) (bj_window *p_window, const bj_cursor_event *, void *) |
Define the callback type for cursor movement events. | |
typedef void(* | bj_button_callback_fn_t) (bj_window *p_window, const bj_button_event *, void *) |
Define the callback type for mouse button events. | |
typedef void(* | bj_key_callback_fn_t) (bj_window *p_window, const bj_key_event *, void *) |
Define the callback type for keyboard key events. | |
Functions | |
const char * | bj_get_key_name (int key) |
Get the string name of a key. | |
bj_cursor_callback_fn_t | bj_set_cursor_callback (bj_cursor_callback_fn_t p_callback, void *p_user_data) |
Set the global callback for cursor events. | |
bj_button_callback_fn_t | bj_set_button_callback (bj_button_callback_fn_t p_callback, void *p_user_data) |
Set the global callback for mouse button events. | |
bj_key_callback_fn_t | bj_set_key_callback (bj_key_callback_fn_t p_callback, void *p_user_data) |
Set the global callback for keyboard key events. | |
bj_enter_callback_fn_t | bj_set_enter_callback (bj_enter_callback_fn_t p_callback, void *p_user_data) |
Set the global callback for mouse enter/leave events. | |
void | bj_close_on_escape (bj_window *, const bj_key_event *, void *p_user_data) |
Handle the ESC key to close a window. | |
void | bj_push_event (const bj_event *e) |
Push a custom event to the internal event queue. | |
void | bj_push_key_event (bj_window *p_window, bj_event_action action, bj_key key, int scancode) |
Push a keyboard event into the event system. | |
void | bj_push_cursor_event (bj_window *p_window, int x, int y) |
Push a cursor movement event. | |
void | bj_push_button_event (bj_window *p_window, int button, bj_event_action action, int x, int y) |
Push a mouse button event. | |
void | bj_push_enter_event (bj_window *p_window, bj_bool enter, int x, int y) |
Push an enter or leave window event. | |
void | bj_dispatch_events (void) |
Poll and dispatch all pending events. | |
bj_bool | bj_poll_events (bj_event *p_event) |
void | bj_dispatch_event (const bj_event *p_event) |
struct bj_enter_event_t |
Data Fields | ||
---|---|---|
bj_bool | enter | BJ_TRUE if entering window, BJ_FALSE if leaving. |
int | x | Cursor x position. |
int | y | Cursor y position. |
struct bj_button_event_t |
Data Fields | ||
---|---|---|
bj_event_action | action | Action (press/release) |
int | button | Button identifier (e.g., BJ_BUTTON_LEFT) |
int | x | Cursor x position. |
int | y | Cursor y position. |
struct bj_key_event_t |
Data Fields | ||
---|---|---|
bj_event_action | action | Action (press/release/repeat) |
bj_key | key | Key identifier. |
int | scancode | Scancode (layout-independent) |
struct bj_event_t |
This union-based structure wraps all types of input events.
Data Fields | ||
---|---|---|
union bj_event_t.__unnamed0__ | __unnamed__ | |
bj_event_type | type | Type of event. |
bj_window * | window | Target window. |
union bj_event_t.__unnamed0__ |
Data Fields | ||
---|---|---|
bj_button_event | button | Button event data. |
bj_cursor_event | cursor | Cursor event data. |
bj_enter_event | enter | Enter/leave event data. |
bj_key_event | key | Key event data. |
typedef void(* bj_button_callback_fn_t) (bj_window *p_window, const bj_button_event *, void *) |
Called when a mouse button is pressed or released.
typedef void(* bj_cursor_callback_fn_t) (bj_window *p_window, const bj_cursor_event *, void *) |
Called when the cursor moves inside a window.
typedef void(* bj_enter_callback_fn_t) (bj_window *, const bj_enter_event *, void *) |
Called when the cursor enters or exits a window.
typedef struct bj_event_t bj_event |
This union-based structure wraps all types of input events.
The values are directly taken from the [VK codes in Microsoft API] (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) This also includes the annotated documentation of each key.
Even if all values from the abovementioned page are present in this enum, not all are used by Banjo and some are never returned by key events.
Values for 0-9 and A-Z keys directly directly correspond to their ASCII equivalent.
typedef void(* bj_key_callback_fn_t) (bj_window *p_window, const bj_key_event *, void *) |
Called when a key is pressed, released, or repeated.
enum bj_event_action_t |
enum bj_event_type_t |
enum bj_key_t |
The values are directly taken from the [VK codes in Microsoft API] (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) This also includes the annotated documentation of each key.
Even if all values from the abovementioned page are present in this enum, not all are used by Banjo and some are never returned by key events.
Values for 0-9 and A-Z keys directly directly correspond to their ASCII equivalent.
void bj_close_on_escape | ( | bj_window * | , |
const bj_key_event * | , | ||
void * | p_user_data ) |
This utility callback closes the window when BJ_KEY_ESCAPE is pressed. Can be passed directly to bj_set_key_callback.
void bj_dispatch_events | ( | void | ) |
This function checks for new input events and invokes the appropriate registered callbacks.
const char * bj_get_key_name | ( | int | key | ) |
void bj_push_button_event | ( | bj_window * | p_window, |
int | button, | ||
bj_event_action | action, | ||
int | x, | ||
int | y ) |
Represents a mouse button press or release within a window.
p_window | Pointer to the window receiving the event. |
button | The mouse button identifier. |
action | The action performed (press or release). |
x | The x-coordinate of the cursor at the event. |
y | The y-coordinate of the cursor at the event. |
void bj_push_cursor_event | ( | bj_window * | p_window, |
int | x, | ||
int | y ) |
Indicates the cursor has moved within the specified window.
p_window | Pointer to the window receiving the event. |
x | The new x-coordinate of the cursor. |
y | The new y-coordinate of the cursor. |
Indicates whether the cursor entered or left the specified window.
p_window | Pointer to the window receiving the event. |
enter | BJ_TRUE if cursor entered the window, BJ_FALSE if left. |
x | The x-coordinate of the cursor at the event. |
y | The y-coordinate of the cursor at the event. |
void bj_push_event | ( | const bj_event * | e | ) |
Typically used by the platform backend to post low-level events into the event processing system.
e | Pointer to the event to push. |
void bj_push_key_event | ( | bj_window * | p_window, |
bj_event_action | action, | ||
bj_key | key, | ||
int | scancode ) |
This function creates and queues a keyboard event reflecting a key press, release, or repeat.
p_window | Pointer to the window receiving the event. |
action | The key event action (press, release, repeat). |
key | The key code that triggered the event. |
scancode | The platform-specific scancode of the key. |
bj_button_callback_fn_t bj_set_button_callback | ( | bj_button_callback_fn_t | p_callback, |
void * | p_user_data ) |
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_cursor_callback_fn_t bj_set_cursor_callback | ( | bj_cursor_callback_fn_t | p_callback, |
void * | p_user_data ) |
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_enter_callback_fn_t bj_set_enter_callback | ( | bj_enter_callback_fn_t | p_callback, |
void * | p_user_data ) |
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_key_callback_fn_t bj_set_key_callback | ( | bj_key_callback_fn_t | p_callback, |
void * | p_user_data ) |
p_callback | The new callback function |
p_user_data | Location to user-provided data. |