Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
Event

Data Structures

struct  bj_enter_event
struct  bj_cursor_event
struct  bj_button_event
struct  bj_key_event
struct  bj_event
union  bj_event.as

Macros

#define BJ_BUTTON_1   1
#define BJ_BUTTON_2   2
#define BJ_BUTTON_3   3
#define BJ_BUTTON_4   4
#define BJ_BUTTON_5   5
#define BJ_BUTTON_LEFT   BJ_BUTTON_1
#define BJ_BUTTON_RIGHT   BJ_BUTTON_3
#define BJ_BUTTON_MIDDLE   BJ_BUTTON_2
#define BJ_BUTTON_UP   BJ_BUTTON_4
#define BJ_BUTTON_DOWN   BJ_BUTTON_5
#define BJ_KEY_APOSTROPHE   BJ_KEY_OEM_7
#define BJ_KEY_BACKSLASH   BJ_KEY_OEM_5
#define BJ_KEY_BACKSPACE   BJ_KEY_BACK
#define BJ_KEY_CAPSLOCK   BJ_KEY_CAPITAL
#define BJ_KEY_COMMA   BJ_KEY_OEM_COMMA
#define BJ_KEY_ENTER   BJ_KEY_RETURN
#define BJ_KEY_GRAVE_ACCENT   BJ_KEY_OEM_3
#define BJ_KEY_HANGUL   BJ_KEY_KANA
#define BJ_KEY_HANJA   BJ_KEY_KANJI
#define BJ_KEY_LEFT_ALT   BJ_KEY_LMENU
#define BJ_KEY_LEFT_BRACKET   BJ_KEY_OEM_4
#define BJ_KEY_LEFT_CONTROL   BJ_KEY_LCONTROL
#define BJ_KEY_LEFT_OS   BJ_KEY_LWIN
#define BJ_KEY_LEFT_SHIT   BJ_KEY_LSHIFT
#define BJ_KEY_MINUS   BJ_KEY_OEM_MINUS
#define BJ_KEY_PAGE_DOWN   BJ_KEY_NEXT
#define BJ_KEY_PAGE_UP   BJ_KEY_PRIOR
#define BJ_KEY_PERIOD   BJ_KEY_OEM_PERIOD
#define BJ_KEY_PLUS   BJ_KEY_OEM_PLUS
#define BJ_KEY_PRINT_SCREEN   BJ_KEY_SNAPSHOT
#define BJ_KEY_RIGHT_ALT   BJ_KEY_RMENU
#define BJ_KEY_RIGHT_BRACKET   BJ_KEY_OEM_6
#define BJ_KEY_RIGHT_CONTROL   BJ_KEY_RCONTROL
#define BJ_KEY_RIGHT_OS   BJ_KEY_RWIN
#define BJ_KEY_RIGHT_SHIFT   BJ_KEY_RSHIFT
#define BJ_KEY_SEMICOLON   BJ_KEY_OEM_1
#define BJ_KEY_SLASH   BJ_KEY_OEM_2

Typedefs

typedef enum bj_key bj_key
typedef enum bj_event_action bj_event_action
typedef enum bj_event_type bj_event_type
typedef void(* bj_enter_callback_fn) (struct bj_window *window, const struct bj_enter_event *event, void *user_data)
typedef void(* bj_cursor_callback_fn) (struct bj_window *window, const struct bj_cursor_event *event, void *user_data)
typedef void(* bj_button_callback_fn) (struct bj_window *window, const struct bj_button_event *event, void *user_data)
typedef void(* bj_key_callback_fn) (struct bj_window *window, const struct bj_key_event *event, void *user_data)

Enumerations

enum  bj_key {
  BJ_KEY_UNKNOWN = 0x00 , BJ_KEY_LBUTTON = 0x01 , BJ_KEY_RBUTTON = 0x02 , BJ_KEY_CANCEL = 0x03 ,
  BJ_KEY_MBUTTON = 0x04 , BJ_KEY_XBUTTON1 = 0x05 , BJ_KEY_XBUTTON2 = 0x06 , BJ_KEY_BACK = 0x08 ,
  BJ_KEY_TAB = 0x09 , BJ_KEY_CLEAR = 0x0C , BJ_KEY_RETURN = 0x0D , BJ_KEY_SHIFT = 0x10 ,
  BJ_KEY_CONTROL = 0x11 , BJ_KEY_MENU = 0x12 , BJ_KEY_PAUSE = 0x13 , BJ_KEY_CAPITAL = 0x14 ,
  BJ_KEY_KANA = 0x15 , BJ_KEY_IME_ON = 0x16 , BJ_KEY_JUNJA = 0x17 , BJ_KEY_FINAL = 0x18 ,
  BJ_KEY_KANJI = 0x19 , BJ_KEY_IME_OFF = 0x1A , BJ_KEY_ESCAPE = 0x1B , BJ_KEY_CONVERT = 0x1C ,
  BJ_KEY_NONCONVERT = 0x1D , BJ_KEY_ACCEPT = 0x1E , BJ_KEY_MODECHAN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RESS , BJ_REPEAT }
enum  bj_event_type { BJ_EVENT_ENTER , BJ_EVENT_CURSOR , BJ_EVENT_KEY , BJ_EVENT_BUTTON }

Functions

const char * bj_key_name (int key)
bj_cursor_callback_fn bj_set_cursor_callback (bj_cursor_callback_fn callback, void *user_data)
bj_button_callback_fn bj_set_button_callback (bj_button_callback_fn callback, void *user_data)
bj_key_callback_fn bj_set_key_callback (bj_key_callback_fn callback, void *user_data)
bj_enter_callback_fn bj_set_enter_callback (bj_enter_callback_fn callback, void *user_data)
void bj_close_on_escape (struct bj_window *window, const struct bj_key_event *event, void *user_data)
void bj_push_event (const struct bj_event *e)
void bj_push_key_event (struct bj_window *window, enum bj_event_action action, enum bj_key key, int scancode)
void bj_push_cursor_event (struct bj_window *window, int x, int y)
void bj_push_button_event (struct bj_window *window, int button, enum bj_event_action action, int x, int y)
void bj_push_enter_event (struct bj_window *window, bj_bool enter, int x, int y)
void bj_dispatch_events (void)
bj_bool bj_poll_events (struct bj_event *event)
void bj_dispatch_event (const struct bj_event *event)

Detailed Description

Pick up keyboard, mouse, and window-focus events from the user.

As the user presses keys, moves the mouse, clicks buttons, or hovers in and out of your window, the operating system collects these moments and hands them to your program. Banjo gathers them into a single queue of events that you process once per frame. There are four event types:

  • **BJ_EVENT_KEY**: a keyboard key was pressed, released, or is being held down repeatedly. Carries the key identifier (e.g. BJ_KEY_W) and the action.
  • **BJ_EVENT_BUTTON**: a mouse button was pressed or released. Carries the button identifier and cursor position.
  • **BJ_EVENT_CURSOR**: the mouse cursor moved. Carries the new position.
  • **BJ_EVENT_ENTER**: the cursor entered or left the window's area.

Banjo offers two styles for consuming events. Both work; pick whichever fits the shape of your program.

Style 1: callbacks (register once, get called when something

happens)

You register a function of yours that Banjo will call whenever the matching event arrives. One register-function per event type: bj_set_cursor_callback, bj_set_button_callback, bj_set_key_callback, bj_set_enter_callback. Then, each frame, you call bj_dispatch_events once and Banjo runs your registered functions for every event that's waiting.

bj_set_key_callback(my_key_handler, /*user_data=*‍/NULL);
while (!bj_should_close_window(window)) {
bj_dispatch_events(); // fires registered callbacks
render();
bj_sleep(15);
}
bj_key_callback_fn bj_set_key_callback(bj_key_callback_fn callback, void *user_data)
Set the global callback for keyboard key events.

The register functions return the previously installed callback, so you can save it and call it from your new callback to chain handlers if you need to. The built-in bj_close_on_escape can be handed straight to bj_set_key_callback for one-line ESC-to-quit support. That's the shortcut start.c uses.

Style 2: polling (you ask Banjo "is there an event for me?")

Instead of registering callbacks, you call bj_poll_events in a loop and Banjo hands you one event at a time until the queue is empty. You decide what to do with each one. This style fits programs whose response to an event depends on per-frame state (so you don't want a callback firing whenever, you want to process events at a specific moment in your update loop) or that need to filter or batch.

struct bj_event ev;
while (bj_poll_events(&ev)) {
switch (ev.type) {
case BJ_EVENT_KEY: handle_key(&ev.as.key); break;
case BJ_EVENT_CURSOR: handle_cursor(&ev.as.cursor); break;
/* ... *‍/
}
}
bj_bool bj_poll_events(struct bj_event *event)
Poll the next pending event from the system queue.
@ BJ_EVENT_KEY
Keyboard key.
Definition event.h:441
@ BJ_EVENT_CURSOR
Mouse move.
Definition event.h:440
Represent a generic window-related event.
Definition event.h:453

You can mix the two styles: a polled event you don't care about can be forwarded to the global callbacks via bj_dispatch_event.

When to use which

  • Use callbacks for one-shot reactions: "ESC pressed → close the window", "the player clicked the mute button". Each event maps to one piece of code; you don't care exactly when it fires.
  • Use polling when you need to react to held-down state ("paddle goes up while W is pressed"). Actually for that case prefer bj_get_key to query the current state directly rather than tracking press/release pairs.
  • Use polling also when you're integrating Banjo's events with your own event system, or want a precise frame-by-frame log of exactly what happened in order.

Key codes

bj_key values follow Microsoft's Virtual-Key codes (so BJ_KEY_A == 0x41, matching ASCII for letters/digits). The aliases at the bottom of this header (BJ_KEY_BACKSPACE, BJ_KEY_ENTER, BJ_KEY_LEFT_ALT, …) wrap the OEM/Windows-style names with their common labels.

Key-repeat events (BJ_REPEAT) only fire on windows that were created with the BJ_WINDOW_FLAG_KEY_REPEAT flag.

See also
event_callbacks.c (callback flow) and event_polling.c (polling flow) for runnable demos. The window subsystem itself is documented under Windows.

Data Structure Documentation

◆ bj_enter_event

struct bj_enter_event

Represent a mouse enter or leave event.

Examples
event_callbacks.c.

Definition at line 402 of file event.h.

Data Fields
bj_bool enter BJ_TRUE if entering window, BJ_FALSE if leaving.
int x Cursor x position.
int y Cursor y position.

◆ bj_cursor_event

struct bj_cursor_event

Represent a mouse cursor movement event.

Examples
event_callbacks.c.

Definition at line 411 of file event.h.

Data Fields
int x Cursor x position.
int y Cursor y position.

◆ bj_button_event

struct bj_button_event

Represent a mouse button event.

Examples
event_callbacks.c.

Definition at line 419 of file event.h.

Data Fields
enum 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.

◆ bj_key_event

struct bj_key_event

Represent a keyboard key event.

Examples
event_callbacks.c, and random_distribution.c.

Definition at line 429 of file event.h.

Data Fields
enum bj_event_action action Action (press/release/repeat)
enum bj_key key Key identifier.
int scancode Scancode (layout-independent)

◆ bj_event

struct bj_event

Represent a generic window-related event.

This union-based structure wraps all types of input events.

Examples
event_polling.c.

Definition at line 453 of file event.h.

Data Fields
union bj_event.as as
enum bj_event_type type Type of event.
struct bj_window * window Target window.

◆ bj_event.as

union bj_event.as

Definition at line 456 of file event.h.

Data Fields
struct bj_button_event button Button event data.
struct bj_cursor_event cursor Cursor event data.
struct bj_enter_event enter Enter/leave event data.
struct bj_key_event key Key event data.

Macro Definition Documentation

◆ BJ_BUTTON_1

#define BJ_BUTTON_1   1

First button.

Definition at line 116 of file event.h.

◆ BJ_BUTTON_2

#define BJ_BUTTON_2   2

Second button.

Definition at line 118 of file event.h.

◆ BJ_BUTTON_3

#define BJ_BUTTON_3   3

Third button.

Definition at line 120 of file event.h.

◆ BJ_BUTTON_4

#define BJ_BUTTON_4   4

Fourth button.

Definition at line 122 of file event.h.

◆ BJ_BUTTON_5

#define BJ_BUTTON_5   5

Fifth button.

Definition at line 124 of file event.h.

◆ BJ_BUTTON_DOWN

#define BJ_BUTTON_DOWN   BJ_BUTTON_5

Scroll down mouse button.

Definition at line 134 of file event.h.

◆ BJ_BUTTON_LEFT

#define BJ_BUTTON_LEFT   BJ_BUTTON_1

Left mouse button.

Definition at line 126 of file event.h.

◆ BJ_BUTTON_MIDDLE

#define BJ_BUTTON_MIDDLE   BJ_BUTTON_2

Middle mouse button.

Definition at line 130 of file event.h.

◆ BJ_BUTTON_RIGHT

#define BJ_BUTTON_RIGHT   BJ_BUTTON_3

Right mouse button.

Definition at line 128 of file event.h.

◆ BJ_BUTTON_UP

#define BJ_BUTTON_UP   BJ_BUTTON_4

Scroll up mouse button.

Definition at line 132 of file event.h.

◆ BJ_KEY_APOSTROPHE

#define BJ_KEY_APOSTROPHE   BJ_KEY_OEM_7

Alias for BJ_KEY_OEM_7.

Definition at line 346 of file event.h.

◆ BJ_KEY_BACKSLASH

#define BJ_KEY_BACKSLASH   BJ_KEY_OEM_5

Alias for BJ_KEY_OEM_5.

Definition at line 347 of file event.h.

◆ BJ_KEY_BACKSPACE

#define BJ_KEY_BACKSPACE   BJ_KEY_BACK

Alias for BJ_KEY_BACK.

Definition at line 348 of file event.h.

◆ BJ_KEY_CAPSLOCK

#define BJ_KEY_CAPSLOCK   BJ_KEY_CAPITAL

Alias for BJ_KEY_CAPITAL.

Definition at line 349 of file event.h.

◆ BJ_KEY_COMMA

#define BJ_KEY_COMMA   BJ_KEY_OEM_COMMA

Alias for BJ_KEY_OEM_COMMA.

Definition at line 350 of file event.h.

◆ BJ_KEY_ENTER

#define BJ_KEY_ENTER   BJ_KEY_RETURN

Alias for BJ_KEY_RETURN.

Definition at line 351 of file event.h.

◆ BJ_KEY_GRAVE_ACCENT

#define BJ_KEY_GRAVE_ACCENT   BJ_KEY_OEM_3

Alias for BJ_KEY_OEM_3.

Definition at line 352 of file event.h.

◆ BJ_KEY_HANGUL

#define BJ_KEY_HANGUL   BJ_KEY_KANA

Alias for BJ_KEY_KANA.

Definition at line 353 of file event.h.

◆ BJ_KEY_HANJA

#define BJ_KEY_HANJA   BJ_KEY_KANJI

Alias for BJ_KEY_KANJI.

Definition at line 354 of file event.h.

◆ BJ_KEY_LEFT_ALT

#define BJ_KEY_LEFT_ALT   BJ_KEY_LMENU

Alias for BJ_KEY_LMENU.

Definition at line 355 of file event.h.

◆ BJ_KEY_LEFT_BRACKET

#define BJ_KEY_LEFT_BRACKET   BJ_KEY_OEM_4

Alias for BJ_KEY_OEM_4.

Definition at line 356 of file event.h.

◆ BJ_KEY_LEFT_CONTROL

#define BJ_KEY_LEFT_CONTROL   BJ_KEY_LCONTROL

Alias for BJ_KEY_LCONTROL.

Definition at line 357 of file event.h.

◆ BJ_KEY_LEFT_OS

#define BJ_KEY_LEFT_OS   BJ_KEY_LWIN

Alias for BJ_KEY_LWIN.

Definition at line 358 of file event.h.

◆ BJ_KEY_LEFT_SHIT

#define BJ_KEY_LEFT_SHIT   BJ_KEY_LSHIFT

Alias for BJ_KEY_LSHIFT.

Definition at line 359 of file event.h.

◆ BJ_KEY_MINUS

#define BJ_KEY_MINUS   BJ_KEY_OEM_MINUS

Alias for BJ_KEY_OEM_MINUS.

Definition at line 360 of file event.h.

◆ BJ_KEY_PAGE_DOWN

#define BJ_KEY_PAGE_DOWN   BJ_KEY_NEXT

Alias for BJ_KEY_NEXT.

Definition at line 361 of file event.h.

◆ BJ_KEY_PAGE_UP

#define BJ_KEY_PAGE_UP   BJ_KEY_PRIOR

Alias for BJ_KEY_PRIOR.

Definition at line 362 of file event.h.

◆ BJ_KEY_PERIOD

#define BJ_KEY_PERIOD   BJ_KEY_OEM_PERIOD

Alias for BJ_KEY_OEM_PERIOD.

Definition at line 363 of file event.h.

◆ BJ_KEY_PLUS

#define BJ_KEY_PLUS   BJ_KEY_OEM_PLUS

Alias for BJ_KEY_OEM_PLUS.

Definition at line 364 of file event.h.

◆ BJ_KEY_PRINT_SCREEN

#define BJ_KEY_PRINT_SCREEN   BJ_KEY_SNAPSHOT

Alias for BJ_KEY_SNAPSHOT.

Definition at line 365 of file event.h.

◆ BJ_KEY_RIGHT_ALT

#define BJ_KEY_RIGHT_ALT   BJ_KEY_RMENU

Alias for BJ_KEY_RMENU.

Definition at line 366 of file event.h.

◆ BJ_KEY_RIGHT_BRACKET

#define BJ_KEY_RIGHT_BRACKET   BJ_KEY_OEM_6

Alias for BJ_KEY_OEM_6.

Definition at line 367 of file event.h.

◆ BJ_KEY_RIGHT_CONTROL

#define BJ_KEY_RIGHT_CONTROL   BJ_KEY_RCONTROL

Alias for BJ_KEY_RCONTROL.

Definition at line 368 of file event.h.

◆ BJ_KEY_RIGHT_OS

#define BJ_KEY_RIGHT_OS   BJ_KEY_RWIN

Alias for BJ_KEY_RWIN.

Definition at line 369 of file event.h.

◆ BJ_KEY_RIGHT_SHIFT

#define BJ_KEY_RIGHT_SHIFT   BJ_KEY_RSHIFT

Alias for BJ_KEY_RSHIFT.

Definition at line 370 of file event.h.

◆ BJ_KEY_SEMICOLON

#define BJ_KEY_SEMICOLON   BJ_KEY_OEM_1

Alias for BJ_KEY_OEM_1.

Definition at line 371 of file event.h.

◆ BJ_KEY_SLASH

#define BJ_KEY_SLASH   BJ_KEY_OEM_2

Alias for BJ_KEY_OEM_2.

Definition at line 372 of file event.h.

Typedef Documentation

◆ bj_button_callback_fn

typedef void(* bj_button_callback_fn) (struct bj_window *window, const struct bj_button_event *event, void *user_data)

Define the callback type for mouse button events.

Called when a mouse button is pressed or released.

See also
bj_set_button_callback

Definition at line 486 of file event.h.

◆ bj_cursor_callback_fn

typedef void(* bj_cursor_callback_fn) (struct bj_window *window, const struct bj_cursor_event *event, void *user_data)

Define the callback type for cursor movement events.

Called when the cursor moves inside a window.

See also
bj_set_cursor_callback

Definition at line 478 of file event.h.

◆ bj_enter_callback_fn

typedef void(* bj_enter_callback_fn) (struct bj_window *window, const struct bj_enter_event *event, void *user_data)

Define the callback type for enter events.

Called when the cursor enters or exits a window.

See also
bj_set_enter_callback

Definition at line 470 of file event.h.

◆ bj_event_action

Definition at line 396 of file event.h.

◆ bj_event_type

Definition at line 445 of file event.h.

◆ bj_key

typedef enum bj_key bj_key

Definition at line 342 of file event.h.

◆ bj_key_callback_fn

typedef void(* bj_key_callback_fn) (struct bj_window *window, const struct bj_key_event *event, void *user_data)

Define the callback type for keyboard key events.

Called when a key is pressed, released, or repeated.

See also
bj_set_key_callback

Definition at line 494 of file event.h.

Enumeration Type Documentation

◆ bj_event_action

Define event action types for keys or mouse buttons.

Enumerator
BJ_RELEASE 

The key or button was released.

BJ_PRESS 

The key or button was pressed.

BJ_REPEAT 

The key is being held (repeats)

Definition at line 390 of file event.h.

◆ bj_event_type

Identify the type of a generic event.

Enumerator
BJ_EVENT_ENTER 

Mouse enter/leave.

BJ_EVENT_CURSOR 

Mouse move.

BJ_EVENT_KEY 

Keyboard key.

BJ_EVENT_BUTTON 

Mouse button.

Definition at line 438 of file event.h.

◆ bj_key

enum bj_key

List of possible keys on a keyboard.

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.

Enumerator
BJ_KEY_UNKNOWN 

No Button.

BJ_KEY_LBUTTON 

Left mouse button.

BJ_KEY_RBUTTON 

Right mouse button.

BJ_KEY_CANCEL 

Control-break processing.

BJ_KEY_MBUTTON 

Middle mouse button.

BJ_KEY_XBUTTON1 

X1 mouse button.

BJ_KEY_XBUTTON2 

X2 mouse button.

BJ_KEY_BACK 

Backspace key.

BJ_KEY_TAB 

Tab key.

BJ_KEY_CLEAR 

Clear key.

BJ_KEY_RETURN 

Enter key.

BJ_KEY_SHIFT 

Shift key.

BJ_KEY_CONTROL 

Ctrl key.

BJ_KEY_MENU 

Alt key.

BJ_KEY_PAUSE 

Pause key.

BJ_KEY_CAPITAL 

Caps lock key.

BJ_KEY_KANA 

IME Kana mode.

BJ_KEY_IME_ON 

IME On.

BJ_KEY_JUNJA 

IME Junja mode.

BJ_KEY_FINAL 

IME final mode.

BJ_KEY_KANJI 

IME Hanja mode.

BJ_KEY_IME_OFF 

IME Off.

BJ_KEY_ESCAPE 

Esc key.

BJ_KEY_CONVERT 

IME convert.

BJ_KEY_NONCONVERT 

IME nonconvert.

BJ_KEY_ACCEPT 

IME accept.

BJ_KEY_MODECHANGE 

IME mode change request.

BJ_KEY_SPACE 

Spacebar key.

BJ_KEY_PRIOR 

Page up key.

BJ_KEY_NEXT 

Page down key.

BJ_KEY_END 

End key.

BJ_KEY_HOME 

Home key.

BJ_KEY_LEFT 

Left arrow key.

BJ_KEY_UP 

Up arrow key.

BJ_KEY_RIGHT 

Right arrow key.

BJ_KEY_DOWN 

Down arrow key.

BJ_KEY_SELECT 

Select key.

BJ_KEY_PRINT 

Print key.

BJ_KEY_EXECUTE 

Execute key.

BJ_KEY_SNAPSHOT 

Print screen key.

BJ_KEY_INSERT 

Insert key.

BJ_KEY_DELETE 

Delete key.

BJ_KEY_HELP 

Help key.

BJ_KEY_0 

0 key

BJ_KEY_1 

1 key

BJ_KEY_2 

2 key

BJ_KEY_3 

3 key

BJ_KEY_4 

4 key

BJ_KEY_5 

5 key

BJ_KEY_6 

6 key

BJ_KEY_7 

7 key

BJ_KEY_8 

8 key

BJ_KEY_9 

9 key

BJ_KEY_A 

A key.

BJ_KEY_B 

B key.

BJ_KEY_C 

C key.

BJ_KEY_D 

D key.

BJ_KEY_E 

E key.

BJ_KEY_F 

F key.

BJ_KEY_G 

G key.

BJ_KEY_H 

H key.

BJ_KEY_I 

I key.

BJ_KEY_J 

J key.

BJ_KEY_K 

K key.

BJ_KEY_L 

L key.

BJ_KEY_M 

M key.

BJ_KEY_N 

N key.

BJ_KEY_O 

O key.

BJ_KEY_P 

P key.

BJ_KEY_Q 

Q key.

BJ_KEY_R 

R key.

BJ_KEY_S 

S key.

BJ_KEY_T 

T key.

BJ_KEY_U 

U key.

BJ_KEY_V 

V key.

BJ_KEY_W 

W key.

BJ_KEY_X 

X key.

BJ_KEY_Y 

Y key.

BJ_KEY_Z 

Z key.

BJ_KEY_LWIN 

Left Windows logo key.

BJ_KEY_RWIN 

Right Windows logo key.

BJ_KEY_APPS 

Application key.

BJ_KEY_SLEEP 

Computer Sleep key.

BJ_KEY_NUMPAD0 

Numeric keypad 0 key.

BJ_KEY_NUMPAD1 

Numeric keypad 1 key.

BJ_KEY_NUMPAD2 

Numeric keypad 2 key.

BJ_KEY_NUMPAD3 

Numeric keypad 3 key.

BJ_KEY_NUMPAD4 

Numeric keypad 4 key.

BJ_KEY_NUMPAD5 

Numeric keypad 5 key.

BJ_KEY_NUMPAD6 

Numeric keypad 6 key.

BJ_KEY_NUMPAD7 

Numeric keypad 7 key.

BJ_KEY_NUMPAD8 

Numeric keypad 8 key.

BJ_KEY_NUMPAD9 

Numeric keypad 9 key.

BJ_KEY_MULTIPLY 

Multiply key.

BJ_KEY_ADD 

Add key.

BJ_KEY_SEPARATOR 

Separator key.

BJ_KEY_SUBTRACT 

Subtract key.

BJ_KEY_DECIMAL 

Decimal key.

BJ_KEY_DIVIDE 

Divide key.

BJ_KEY_F1 

F1 key.

BJ_KEY_F2 

F2 key.

BJ_KEY_F3 

F3 key.

BJ_KEY_F4 

F4 key.

BJ_KEY_F5 

F5 key.

BJ_KEY_F6 

F6 key.

BJ_KEY_F7 

F7 key.

BJ_KEY_F8 

F8 key.

BJ_KEY_F9 

F9 key.

BJ_KEY_F10 

F10 key.

BJ_KEY_F11 

F11 key.

BJ_KEY_F12 

F12 key.

BJ_KEY_F13 

F13 key.

BJ_KEY_F14 

F14 key.

BJ_KEY_F15 

F15 key.

BJ_KEY_F16 

F16 key.

BJ_KEY_F17 

F17 key.

BJ_KEY_F18 

F18 key.

BJ_KEY_F19 

F19 key.

BJ_KEY_F20 

F20 key.

BJ_KEY_F21 

F21 key.

BJ_KEY_F22 

F22 key.

BJ_KEY_F23 

F23 key.

BJ_KEY_F24 

F24 key.

BJ_KEY_NUMLOCK 

Num lock key.

BJ_KEY_SCROLL 

Scroll lock key.

BJ_KEY_LSHIFT 

Left Shift key.

BJ_KEY_RSHIFT 

Right Shift key.

BJ_KEY_LCONTROL 

Left Ctrl key.

BJ_KEY_RCONTROL 

Right Ctrl key.

BJ_KEY_LMENU 

Left Alt key.

BJ_KEY_RMENU 

Right Alt key.

BJ_KEY_BROWSER_BACK 

Browser Back key.

BJ_KEY_BROWSER_FORWARD 

Browser Forward key.

BJ_KEY_BROWSER_REFRESH 

Browser Refresh key.

BJ_KEY_BROWSER_STOP 

Browser Stop key.

BJ_KEY_BROWSER_SEARCH 

Browser Search key.

BJ_KEY_BROWSER_FAVORITES 

Browser Favorites key.

BJ_KEY_BROWSER_HOME 

Browser Start and Home key.

BJ_KEY_VOLUME_MUTE 

Volume Mute key.

BJ_KEY_VOLUME_DOWN 

Volume Down key.

BJ_KEY_VOLUME_UP 

Volume Up key.

BJ_KEY_MEDIA_NEXT_TRACK 

Next Track key.

BJ_KEY_MEDIA_PREV_TRACK 

Previous Track key.

BJ_KEY_MEDIA_STOP 

Stop Media key.

BJ_KEY_MEDIA_PLAY_PAUSE 

Play/Pause Media key.

BJ_KEY_LAUNCH_MAIL 

Start Mail key.

BJ_KEY_LAUNCH_MEDIA_SELECT 

Select Media key.

BJ_KEY_LAUNCH_APP1 

Start Application 1 key.

BJ_KEY_LAUNCH_APP2 

Start Application 2 key.

BJ_KEY_OEM_1 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the ;: key

BJ_KEY_OEM_PLUS 

For any country/region, the + key.

BJ_KEY_OEM_COMMA 

For any country/region, the , key.

BJ_KEY_OEM_MINUS 

For any country/region, the - key.

BJ_KEY_OEM_PERIOD 

For any country/region, the .

key

BJ_KEY_OEM_2 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the /? key

BJ_KEY_OEM_3 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the `~ key

BJ_KEY_OEM_4 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the [{ key

BJ_KEY_OEM_5 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the \| key

BJ_KEY_OEM_6 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the ]} key

BJ_KEY_OEM_7 

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the '" key

BJ_KEY_OEM_8 

Used for miscellaneous characters; it can vary by keyboard.

BJ_KEY_OEM_102 

The <> keys on the US standard keyboard, or the \| key on the non-US 102-key keyboard.

BJ_KEY_PROCESSKEY 

IME PROCESS key.

BJ_KEY_PACKET 

Used to pass Unicode characters as if they were keystrokes.

The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP

BJ_KEY_ATTN 

Attn key.

BJ_KEY_CRSEL 

CrSel key.

BJ_KEY_EXSEL 

ExSel key.

BJ_KEY_EREOF 

Erase EOF key.

BJ_KEY_PLAY 

Play key.

BJ_KEY_ZOOM 

Zoom key.

BJ_KEY_NONAME 

Reserved.

BJ_KEY_PA1 

PA1 key.

BJ_KEY_OEM_CLEAR 

Clear key.

Definition at line 150 of file event.h.

Function Documentation

◆ bj_close_on_escape()

void bj_close_on_escape ( struct bj_window * window,
const struct bj_key_event * event,
void * user_data )

Handle the ESC key to close a window.

This utility callback closes the window when BJ_KEY_ESCAPE is pressed. Can be passed directly to bj_set_key_callback or called manually by your event system.

Parameters
windowTarget window pointer (must not be NULL).
eventKey event data (must not be NULL).
user_dataOpaque user pointer provided at callback registration. Not used by this function.
See also
bj_key_callback_fn
bj_set_key_callback
Examples
bitmap_blit.c, bitmap_blit_colorkey.c, drawing_2d.c, drawing_text.c, interpolation.c, load_bmp.c, physics_kinematics.c, physics_particle.c, pong.c, shaders.c, sprite_animation.c, start.c, and window.c.

Referenced by setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), and setup().

◆ bj_dispatch_event()

void bj_dispatch_event ( const struct bj_event * event)

Dispatch a single event to registered callbacks.

Invokes the appropriate callback(s) associated with the event type. Does not take ownership of event; the caller manages its lifetime.

Parameters
eventPointer to the event to dispatch (must not be NULL).

◆ bj_dispatch_events()

void bj_dispatch_events ( void )

◆ bj_key_name()

const char * bj_key_name ( int key)

Get the string name of a key.

Return a string representing the key code. The returned string omits the BJ_KEY_ prefix.

Parameters
keyThe bj_key value.
Returns
A null-terminated string owned by Banjo.
See also
enum bj_key
Examples
event_callbacks.c, and event_polling.c.

Referenced by key_callback(), and step().

◆ bj_poll_events()

bj_bool bj_poll_events ( struct bj_event * event)

Poll the next pending event from the system queue.

Retrieves and removes the next event, if any.
If no events are available, returns BJ_FALSE and does not modify event.

Parameters
eventPointer to a struct bj_event structure to be filled (must not be NULL).
Return values
BJ_TRUEAn event was retrieved and written to event.
BJ_FALSENo event available.
Examples
event_polling.c.

Referenced by step().

◆ bj_push_button_event()

void bj_push_button_event ( struct bj_window * window,
int button,
enum bj_event_action action,
int x,
int y )

Push a mouse button event.

Represents a mouse button press or release within a window.

Parameters
windowPointer to the window receiving the event.
buttonThe mouse button identifier.
actionThe action performed (press or release).
xThe x-coordinate of the cursor at the event.
yThe y-coordinate of the cursor at the event.

◆ bj_push_cursor_event()

void bj_push_cursor_event ( struct bj_window * window,
int x,
int y )

Push a cursor movement event.

Indicates the cursor has moved within the specified window.

Parameters
windowPointer to the window receiving the event.
xThe new x-coordinate of the cursor.
yThe new y-coordinate of the cursor.

◆ bj_push_enter_event()

void bj_push_enter_event ( struct bj_window * window,
bj_bool enter,
int x,
int y )

Push an enter or leave window event.

Indicates whether the cursor entered or left the specified window.

Parameters
windowPointer to the window receiving the event.
enterBJ_TRUE if cursor entered the window, BJ_FALSE if left.
xThe x-coordinate of the cursor at the event.
yThe y-coordinate of the cursor at the event.

◆ bj_push_event()

void bj_push_event ( const struct bj_event * e)

Push a custom event to the internal event queue.

Typically used by the platform backend to post low-level events into the event processing system.

Parameters
ePointer to the event to push.
Note
The event is copied internally and queued for later dispatch.

◆ bj_push_key_event()

void bj_push_key_event ( struct bj_window * window,
enum bj_event_action action,
enum bj_key key,
int scancode )

Push a keyboard event into the event system.

This function creates and queues a keyboard event reflecting a key press, release, or repeat.

Parameters
windowPointer to the window receiving the event.
actionThe key event action (press, release, repeat).
keyThe key code that triggered the event.
scancodeThe platform-specific scancode of the key.

◆ bj_set_button_callback()

bj_button_callback_fn bj_set_button_callback ( bj_button_callback_fn callback,
void * user_data )

Set the global callback for mouse button events.

Parameters
callbackThe new callback function
user_dataLocation to user-provided data.
Returns
The previously set callback, or NULL if none
See also
bj_button_callback_fn
Examples
event_callbacks.c.

Referenced by setup().

◆ bj_set_cursor_callback()

bj_cursor_callback_fn bj_set_cursor_callback ( bj_cursor_callback_fn callback,
void * user_data )

Set the global callback for cursor events.

Parameters
callbackThe new callback function
user_dataLocation to user-provided data.
Returns
The previously set callback, or NULL if none
See also
bj_cursor_callback_fn
Examples
event_callbacks.c.

Referenced by setup().

◆ bj_set_enter_callback()

bj_enter_callback_fn bj_set_enter_callback ( bj_enter_callback_fn callback,
void * user_data )

Set the global callback for mouse enter/leave events.

Parameters
callbackThe new callback function
user_dataLocation to user-provided data.
Returns
The previously set callback, or NULL if none
See also
bj_enter_callback_fn
Examples
event_callbacks.c.

Referenced by setup().

◆ bj_set_key_callback()

bj_key_callback_fn bj_set_key_callback ( bj_key_callback_fn callback,
void * user_data )

Set the global callback for keyboard key events.

Parameters
callbackThe new callback function
user_dataLocation to user-provided data.
Returns
The previously set callback, or NULL if none
Key Repeat
If the window has the BJ_WINDOW_FLAG_KEY_REPEAT flag set, BJ_REPEAT actions will be sent when holding keys.
See also
bj_key_callback_fn
Examples
bitmap_blit.c, bitmap_blit_colorkey.c, drawing_2d.c, drawing_text.c, event_callbacks.c, interpolation.c, load_bmp.c, physics_kinematics.c, physics_particle.c, pong.c, random_distribution.c, shaders.c, sprite_animation.c, start.c, and window.c.

Referenced by setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), setup(), and setup().