kiba-engine
Typedefs | Enumerations | Functions
input.h File Reference

Input abstraction layer. More...

#include <kiba/defines.h>
Include dependency graph for input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum key_code key_code
 All available keycodes.
 

Enumerations

enum  key_code {
  KEY_MOUSE_LEFT , KEY_MOUSE_RIGHT , KEY_MOUSE_MIDDLE , KEY_BACKSPACE ,
  KEY_ENTER , KEY_TAB , KEY_SHIFT_L , KEY_SHIFT_R ,
  KEY_CONTROL_L , KEY_CONTROL_R , KEY_ALT_L , KEY_ALT_R ,
  KEY_SUPER_L , KEY_SUPER_R , KEY_PAUSE , KEY_CAPITAL ,
  KEY_ESCAPE , KEY_SPACE , KEY_HOME , KEY_END ,
  KEY_PAGE_UP , KEY_PAGE_DOWN , KEY_LEFT , KEY_UP ,
  KEY_DOWN , KEY_RIGHT , KEY_PRINT , KEY_INSERT ,
  KEY_DELETE , KEY_A , KEY_B , KEY_C ,
  KEY_D , KEY_E , KEY_F , KEY_G ,
  KEY_H , KEY_I , KEY_J , KEY_K ,
  KEY_L , KEY_M , KEY_N , KEY_O ,
  KEY_P , KEY_Q , KEY_R , KEY_S ,
  KEY_T , KEY_U , KEY_V , KEY_W ,
  KEY_X , KEY_Y , KEY_Z , KEY_SEMICOLON ,
  KEY_PLUS , KEY_EQUAL , KEY_COMMA , KEY_MINUS ,
  KEY_PERIOD , KEY_SLASH , KEY_GRAVE , KEY_QUOTE ,
  KEY_BRACKET_L , KEY_BRACKET_R , KEY_BACK_SLASH , KEY_0 ,
  KEY_1 , KEY_2 , KEY_3 , KEY_4 ,
  KEY_5 , KEY_6 , KEY_7 , KEY_8 ,
  KEY_9 , KEY_NUMPAD0 , KEY_NUMPAD1 , KEY_NUMPAD2 ,
  KEY_NUMPAD3 , KEY_NUMPAD4 , KEY_NUMPAD5 , KEY_NUMPAD6 ,
  KEY_NUMPAD7 , KEY_NUMPAD8 , KEY_NUMPAD9 , KEY_NUMPAD_ENTER ,
  KEY_SEPARATOR , KEY_DECIMAL , KEY_ADD , KEY_MULTIPLY ,
  KEY_SUBTRACT , KEY_DIVIDE , KEY_NUMLOCK , KEY_F1 ,
  KEY_F2 , KEY_F3 , KEY_F4 , KEY_F5 ,
  KEY_F6 , KEY_F7 , KEY_F8 , KEY_F9 ,
  KEY_F10 , KEY_F11 , KEY_F12 , KEY_F13 ,
  KEY_F14 , KEY_F15 , KEY_F16 , KEY_F17 ,
  KEY_F18 , KEY_F19 , KEY_F20 , KEY_F21 ,
  KEY_F22 , KEY_F23 , KEY_F24 , KEY_CODE_MAX
}
 All available keycodes.
 

Functions

b8 input_initialize (void)
 Initialize the input system. More...
 
void input_shutdown (void)
 Shutdown input system.
 
void input_update (f64 delta_time)
 Updates the input system. More...
 
KB_API b8 input_is_key_down (key_code key)
 Check if a key is currently down. More...
 
KB_API b8 input_was_key_down (key_code key)
 Check if a key was down before the last update. More...
 
KB_API b8 input_is_key_up (key_code key)
 Check if a key is currently up. More...
 
KB_API b8 input_was_key_up (key_code key)
 Check if a key was up before the last update. More...
 
KB_API b8 input_is_key_held (key_code key)
 Check if a key is held. More...
 
KB_API void input_mouse_position (u32 *x, u32 *y)
 Get current mouse position. More...
 
KB_API b8 input_mouse_moved (u32 *x, u32 *y)
 Check if mouse moved. More...
 
KB_API i8 input_mouse_wheel (void)
 Get current mouse wheel scrolling direction. More...
 
void input_process_key (key_code key, b8 pressed)
 Set current state for a key. More...
 
void input_process_mouse_position (u32 x, u32 y)
 Set current state for the mouse position. More...
 
void input_process_mouse_wheel (i8 wheel_pos)
 Set current scrolling wheel direction for the mouse. More...
 

Detailed Description

Input abstraction layer.

Treats input as a state that can be queried at any time.

Definition in file input.h.

Function Documentation

◆ input_initialize()

b8 input_initialize ( void  )

Initialize the input system.

Prepares the internal state to process and serve input information. Must be called once before using the input system.

Returns
false if an error occurred, true if succesful

Definition at line 43 of file input.c.

Here is the call graph for this function:

◆ input_is_key_down()

KB_API b8 input_is_key_down ( key_code  key)

Check if a key is currently down.

Parameters
keythe key_code of the key to check
Returns
true if the key is currently down, false otherwise

Definition at line 57 of file input.c.

◆ input_is_key_held()

KB_API b8 input_is_key_held ( key_code  key)

Check if a key is held.

A key is being held when it was down and is currently still down.

Parameters
keythe key_code of the key to check
Returns
true if the key is held, false otherwise

Definition at line 77 of file input.c.

◆ input_is_key_up()

KB_API b8 input_is_key_up ( key_code  key)

Check if a key is currently up.

Parameters
keythe key_code of the key to check
Returns
true if the key is currently up, false otherwise

Definition at line 67 of file input.c.

◆ input_mouse_moved()

KB_API b8 input_mouse_moved ( u32 *  x,
u32 *  y 
)

Check if mouse moved.

Parameters
xpoints to x delta of the mouse since last update, will be populated by the function
ypoints to y delta of the mouse since last update, will be populated by the function
Returns
false if mouse did not move since last update, true if it moved

Definition at line 87 of file input.c.

◆ input_mouse_position()

KB_API void input_mouse_position ( u32 *  x,
u32 *  y 
)

Get current mouse position.

Parameters
xpoints to x coordinate of the mouse, will be populated by the function
ypoints to y coordinate of the mouse, will be populated by the function

Definition at line 82 of file input.c.

◆ input_mouse_wheel()

KB_API i8 input_mouse_wheel ( void  )

Get current mouse wheel scrolling direction.

Returns
1 if scrolling down, -1 if scrolling up, 0 if no input

Definition at line 93 of file input.c.

◆ input_process_key()

void input_process_key ( key_code  key,
b8  pressed 
)

Set current state for a key.

Parameters
keythe key_code of the key to update
pressedthe current state of the key

Definition at line 95 of file input.c.

◆ input_process_mouse_position()

void input_process_mouse_position ( u32  x,
u32  y 
)

Set current state for the mouse position.

Parameters
xthe current x coordinate of the mouse
ythe current y coordinate of the mouse

Definition at line 100 of file input.c.

◆ input_process_mouse_wheel()

void input_process_mouse_wheel ( i8  wheel_pos)

Set current scrolling wheel direction for the mouse.

Parameters
wheel_posthe current direction of the mouse wheel

Definition at line 105 of file input.c.

◆ input_update()

void input_update ( f64  delta_time)

Updates the input system.

This should be called every frame before prolling window events.

Parameters
delta_timethe time that passed since the last update

Definition at line 51 of file input.c.

Here is the call graph for this function:

◆ input_was_key_down()

KB_API b8 input_was_key_down ( key_code  key)

Check if a key was down before the last update.

Parameters
keythe key_code of the key to check
Returns
true if the key was down, false otherwise

Definition at line 62 of file input.c.

◆ input_was_key_up()

KB_API b8 input_was_key_up ( key_code  key)

Check if a key was up before the last update.

Parameters
keythe key_code of the key to check
Returns
true if the key was up, false otherwise

Definition at line 72 of file input.c.