LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_keyboard.c File Reference

Functions

uint8_t lg_get_special_keys_state (uint32_t *key)
 
void lg_get_motion_and_shot_from_keyboard (int *motion_x, int *motion_y, zboolean *shot, uint32_t *key)
 
void lg_wait_for_key_pressed (uint32_t key)
 
uint32_t lg_wait_for_key_from_set_pressed (int n_keys, uint32_t key[LG_N_KEYS_MAX])
 
uint32_t lg_wait_for_any_key_pressed ()
 
uint32_t lg_return_key_pressed ()
 
void lg_flush_keyb_buf ()
 

Detailed Description

 === Keyboard-related stuff ===

Function Documentation

◆ lg_get_special_keys_state()

uint8_t lg_get_special_keys_state ( uint32_t *  key)

Get arrow (<left>, <right>, <up>, <down>) and other special keys (<enter>, <esc>, <space, and <F1> -> <F12>) state

Return an arrow keys mask and set 'key' param

=== This is the func you can/should use to get keyboard inputs inside the game main loop ===

Do NOT invoke SDL_PollEvent(), unlike other funcs here

Returns
Pressed arrow keys, use AKM_LEFT, AKM_RIGHT, AKM_UP, AKM_DOWN bitmasks to figure out keys

◆ lg_get_motion_and_shot_from_keyboard()

void lg_get_motion_and_shot_from_keyboard ( int *  motion_x,
int *  motion_y,
zboolean *  shot,
uint32_t *  key 
)

Get motion and shot from keyboard

Used in BASP - check/update or use lg_get_special_keys_state() instead

Parameters
motion_xPointer to int, returned value = 0 / +1 / -1
motion_yPointer to int, returned value = 0 / +1 / -1
shotPointer to zboolean, returned value = TRUE / FALSE
keyPointer to uint32_t//unsigned long, returned value = pressed key (0 if none)

◆ lg_wait_for_key_pressed()

void lg_wait_for_key_pressed ( uint32_t  key)

Wait until a specific key is pressed

Parameters
keyThe specific key

◆ lg_wait_for_key_from_set_pressed()

uint32_t lg_wait_for_key_from_set_pressed ( int  n_keys,
uint32_t  key[LG_N_KEYS_MAX] 
)

Wait until a key from a key set is pressed

Parameters
n_keysNum of keys
key[LG_N_KEYS_MAX]A key set
Returns
The pressed key

◆ lg_wait_for_any_key_pressed()

uint32_t lg_wait_for_any_key_pressed ( )

Wait until a key (any key) is pressed

Returns
The pressed key

◆ lg_return_key_pressed()

uint32_t lg_return_key_pressed ( )

Get last pressed key - //doesn't remove the event in this case (event.type == SDL_KEYDOWN)

Returns
Last pressed key, 0 means no key was pressed

◆ lg_flush_keyb_buf()

void lg_flush_keyb_buf ( )

Flush keyboard buffer