Kohi Game Engine
input.h File Reference

This file contains everything having to do with input on deskop environments from keyboards and mice. Gamepads and touch controls will likely be handled separately at a future date. More...

#include "defines.h"

Go to the source code of this file.

Typedefs

typedef enum buttons buttons
 Represents available mouse buttons. More...
 
typedef enum keys keys
 Represents available keyboard keys. More...
 

Enumerations

enum  buttons { BUTTON_LEFT , BUTTON_RIGHT , BUTTON_MIDDLE , BUTTON_MAX_BUTTONS }
 Represents available mouse buttons. More...
 
enum  keys {
  KEY_BACKSPACE = 0x08 , KEY_ENTER = 0x0D , KEY_TAB = 0x09 , KEY_SHIFT = 0x10 ,
  KEY_CONTROL = 0x11 , KEY_PAUSE = 0x13 , KEY_CAPITAL = 0x14 , KEY_ESCAPE = 0x1B ,
  KEY_CONVERT = 0x1C , KEY_NONCONVERT = 0x1D , KEY_ACCEPT = 0x1E , KEY_MODECHANGE = 0x1F ,
  KEY_SPACE = 0x20 , KEY_PAGEUP = 0x21 , KEY_PAGEDOWN = 0x22 , KEY_END = 0x23 ,
  KEY_HOME = 0x24 , KEY_LEFT = 0x25 , KEY_UP = 0x26 , KEY_RIGHT = 0x27 ,
  KEY_DOWN = 0x28 , KEY_SELECT = 0x29 , KEY_PRINT = 0x2A , KEY_EXECUTE = 0x2B ,
  KEY_PRINTSCREEN = 0x2C , KEY_INSERT = 0x2D , KEY_DELETE = 0x2E , KEY_HELP = 0x2F ,
  KEY_0 = 0x30 , KEY_1 = 0x31 , KEY_2 = 0x32 , KEY_3 = 0x33 ,
  KEY_4 = 0x34 , KEY_5 = 0x35 , KEY_6 = 0x36 , KEY_7 = 0x37 ,
  KEY_8 = 0x38 , KEY_9 = 0x39 , KEY_A = 0x41 , KEY_B = 0x42 ,
  KEY_C = 0x43 , KEY_D = 0x44 , KEY_E = 0x45 , KEY_F = 0x46 ,
  KEY_G = 0x47 , KEY_H = 0x48 , KEY_I = 0x49 , KEY_J = 0x4A ,
  KEY_K = 0x4B , KEY_L = 0x4C , KEY_M = 0x4D , KEY_N = 0x4E ,
  KEY_O = 0x4F , KEY_P = 0x50 , KEY_Q = 0x51 , KEY_R = 0x52 ,
  KEY_S = 0x53 , KEY_T = 0x54 , KEY_U = 0x55 , KEY_V = 0x56 ,
  KEY_W = 0x57 , KEY_X = 0x58 , KEY_Y = 0x59 , KEY_Z = 0x5A ,
  KEY_LSUPER = 0x5B , KEY_RSUPER = 0x5C , KEY_APPS = 0x5D , KEY_SLEEP = 0x5F ,
  KEY_NUMPAD0 = 0x60 , KEY_NUMPAD1 = 0x61 , KEY_NUMPAD2 = 0x62 , KEY_NUMPAD3 = 0x63 ,
  KEY_NUMPAD4 = 0x64 , KEY_NUMPAD5 = 0x65 , KEY_NUMPAD6 = 0x66 , KEY_NUMPAD7 = 0x67 ,
  KEY_NUMPAD8 = 0x68 , KEY_NUMPAD9 = 0x69 , KEY_MULTIPLY = 0x6A , KEY_ADD = 0x6B ,
  KEY_SEPARATOR = 0x6C , KEY_SUBTRACT = 0x6D , KEY_DECIMAL = 0x6E , KEY_DIVIDE = 0x6F ,
  KEY_F1 = 0x70 , KEY_F2 = 0x71 , KEY_F3 = 0x72 , KEY_F4 = 0x73 ,
  KEY_F5 = 0x74 , KEY_F6 = 0x75 , KEY_F7 = 0x76 , KEY_F8 = 0x77 ,
  KEY_F9 = 0x78 , KEY_F10 = 0x79 , KEY_F11 = 0x7A , KEY_F12 = 0x7B ,
  KEY_F13 = 0x7C , KEY_F14 = 0x7D , KEY_F15 = 0x7E , KEY_F16 = 0x7F ,
  KEY_F17 = 0x80 , KEY_F18 = 0x81 , KEY_F19 = 0x82 , KEY_F20 = 0x83 ,
  KEY_F21 = 0x84 , KEY_F22 = 0x85 , KEY_F23 = 0x86 , KEY_F24 = 0x87 ,
  KEY_NUMLOCK = 0x90 , KEY_SCROLL = 0x91 , KEY_NUMPAD_EQUAL = 0x92 , KEY_LSHIFT = 0xA0 ,
  KEY_RSHIFT = 0xA1 , KEY_LCONTROL = 0xA2 , KEY_RCONTROL = 0xA3 , KEY_LALT = 0xA4 ,
  KEY_RALT = 0xA5 , KEY_SEMICOLON = 0x3B , KEY_APOSTROPHE = 0xDE , KEY_QUOTE = KEY_APOSTROPHE ,
  KEY_EQUAL = 0xBB , KEY_COMMA = 0xBC , KEY_MINUS = 0xBD , KEY_PERIOD = 0xBE ,
  KEY_SLASH = 0xBF , KEY_GRAVE = 0xC0 , KEY_LBRACKET = 0xDB , KEY_PIPE = 0xDC ,
  KEY_BACKSLASH = KEY_PIPE , KEY_RBRACKET = 0xDD , KEYS_MAX_KEYS = 0xFF
}
 Represents available keyboard keys. More...
 

Functions

b8 input_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the input system. Call twice; once to obtain memory requirement (passing state = 0), then a second time passing allocated memory to state. More...
 
void input_system_shutdown (void *state)
 Shuts the input system down. More...
 
void input_update (const struct frame_data *p_frame_data)
 Updates the input system every frame. More...
 
KAPI b8 input_is_key_down (keys key)
 Indicates if the given key is currently pressed down. More...
 
KAPI b8 input_is_key_up (keys key)
 Indicates if the given key is NOT currently pressed down. More...
 
KAPI b8 input_was_key_down (keys key)
 Indicates if the given key was previously pressed down on the last frame. More...
 
KAPI b8 input_was_key_up (keys key)
 Indicates if the given key was previously pressed down in the last frame. More...
 
void input_process_key (keys key, b8 pressed)
 Sets the state for the given key. More...
 
KAPI b8 input_is_button_down (buttons button)
 Indicates if the given mouse button is currently pressed. More...
 
KAPI b8 input_is_button_up (buttons button)
 Indicates if the given mouse button is currently released. More...
 
KAPI b8 input_was_button_down (buttons button)
 Indicates if the given mouse button was previously pressed in the last frame. More...
 
KAPI b8 input_was_button_up (buttons button)
 Indicates if the given mouse button was previously released in the last frame. More...
 
KAPI b8 input_is_button_dragging (buttons button)
 Indicates if the mouse is currently being dragged with the provided button being held down. More...
 
KAPI void input_get_mouse_position (i32 *x, i32 *y)
 Obtains the current mouse position. More...
 
KAPI void input_get_previous_mouse_position (i32 *x, i32 *y)
 Obtains the previous mouse position. More...
 
void input_process_button (buttons button, b8 pressed)
 Sets the press state of the given mouse button. More...
 
void input_process_mouse_move (i16 x, i16 y)
 Sets the current position of the mouse to the given x and y positions. Also updates the previous position beforehand. More...
 
void input_process_mouse_wheel (i8 z_delta)
 Processes mouse wheel scrolling. More...
 
KAPI const char * input_keycode_str (keys key)
 Returns a string representation of the provided key. Ex. "tab" for the tab key. More...
 
KAPI void input_keymap_push (const struct keymap *map)
 Pushes a new keymap onto the keymap stack, making it the active keymap. A copy of the keymap is taken when pushing onto the stack. More...
 
KAPI b8 input_keymap_pop (void)
 Attempts to pop the top-most keymap from the stack, if there is one. More...
 

Detailed Description

This file contains everything having to do with input on deskop environments from keyboards and mice. Gamepads and touch controls will likely be handled separately at a future date.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-10

Typedef Documentation

◆ buttons

typedef enum buttons buttons

Represents available mouse buttons.

◆ keys

typedef enum keys keys

Represents available keyboard keys.

Enumeration Type Documentation

◆ buttons

enum buttons

Represents available mouse buttons.

Enumerator
BUTTON_LEFT 

The left mouse button.

BUTTON_RIGHT 

The right mouse button.

BUTTON_MIDDLE 

The middle mouse button (typically the wheel)

BUTTON_MAX_BUTTONS 

◆ keys

enum keys

Represents available keyboard keys.

Enumerator
KEY_BACKSPACE 

The backspace key.

KEY_ENTER 

The enter key.

KEY_TAB 

The tab key.

KEY_SHIFT 

The shift key.

KEY_CONTROL 

The Control/Ctrl key.

KEY_PAUSE 

The pause key.

KEY_CAPITAL 

The Caps Lock key.

KEY_ESCAPE 

The Escape key.

KEY_CONVERT 
KEY_NONCONVERT 
KEY_ACCEPT 
KEY_MODECHANGE 
KEY_SPACE 

The spacebar key.

KEY_PAGEUP 

The page up key.

KEY_PAGEDOWN 

The page down key.

KEY_END 

The end key.

KEY_HOME 

The home key.

KEY_LEFT 

The left arrow key.

KEY_UP 

The up arrow key.

KEY_RIGHT 

The right arrow key.

KEY_DOWN 

The down arrow key.

KEY_SELECT 
KEY_PRINT 
KEY_EXECUTE 
KEY_PRINTSCREEN 

The Print Screen key.

KEY_INSERT 

The insert key.

KEY_DELETE 

The delete key.

KEY_HELP 
KEY_0 

The 0 key.

KEY_1 

The 1 key.

KEY_2 

The 2 key.

KEY_3 

The 3 key.

KEY_4 

The 4 key.

KEY_5 

The 5 key.

KEY_6 

The 6 key.

KEY_7 

The 7 key.

KEY_8 

The 8 key.

KEY_9 

The 9 key.

KEY_A 

The A key.

KEY_B 

The B key.

KEY_C 

The C key.

KEY_D 

The D key.

KEY_E 

The E key.

KEY_F 

The F key.

KEY_G 

The G key.

KEY_H 

The H key.

KEY_I 

The I key.

KEY_J 

The J key.

KEY_K 

The K key.

KEY_L 

The L key.

KEY_M 

The M key.

KEY_N 

The N key.

KEY_O 

The O key.

KEY_P 

The P key.

KEY_Q 

The Q key.

KEY_R 

The R key.

KEY_S 

The S key.

KEY_T 

The T key.

KEY_U 

The U key.

KEY_V 

The V key.

KEY_W 

The W key.

KEY_X 

The X key.

KEY_Y 

The Y key.

KEY_Z 

The Z key.

KEY_LSUPER 

The left Windows/Super key.

KEY_RSUPER 

The right Windows/Super key.

KEY_APPS 

The applicatons key.

KEY_SLEEP 

The sleep key.

KEY_NUMPAD0 

The numberpad 0 key.

KEY_NUMPAD1 

The numberpad 1 key.

KEY_NUMPAD2 

The numberpad 2 key.

KEY_NUMPAD3 

The numberpad 3 key.

KEY_NUMPAD4 

The numberpad 4 key.

KEY_NUMPAD5 

The numberpad 5 key.

KEY_NUMPAD6 

The numberpad 6 key.

KEY_NUMPAD7 

The numberpad 7 key.

KEY_NUMPAD8 

The numberpad 8 key.

KEY_NUMPAD9 

The numberpad 9 key.

KEY_MULTIPLY 

The numberpad multiply key.

KEY_ADD 

The numberpad add key.

KEY_SEPARATOR 

The numberpad separator key.

KEY_SUBTRACT 

The numberpad subtract key.

KEY_DECIMAL 

The numberpad decimal key.

KEY_DIVIDE 

The numberpad divide key.

KEY_F1 

The F1 key.

KEY_F2 

The F2 key.

KEY_F3 

The F3 key.

KEY_F4 

The F4 key.

KEY_F5 

The F5 key.

KEY_F6 

The F6 key.

KEY_F7 

The F7 key.

KEY_F8 

The F8 key.

KEY_F9 

The F9 key.

KEY_F10 

The F10 key.

KEY_F11 

The F11 key.

KEY_F12 

The F12 key.

KEY_F13 

The F13 key.

KEY_F14 

The F14 key.

KEY_F15 

The F15 key.

KEY_F16 

The F16 key.

KEY_F17 

The F17 key.

KEY_F18 

The F18 key.

KEY_F19 

The F19 key.

KEY_F20 

The F20 key.

KEY_F21 

The F21 key.

KEY_F22 

The F22 key.

KEY_F23 

The F23 key.

KEY_F24 

The F24 key.

KEY_NUMLOCK 

The number lock key.

KEY_SCROLL 

The scroll lock key.

KEY_NUMPAD_EQUAL 

The numberpad equal key.

KEY_LSHIFT 

The left shift key.

KEY_RSHIFT 

The right shift key.

KEY_LCONTROL 

The left control key.

KEY_RCONTROL 

The right control key.

KEY_LALT 

The left alt key.

KEY_RALT 

The right alt key.

KEY_SEMICOLON 

The semicolon key.

KEY_APOSTROPHE 

The apostrophe/single-quote key.

KEY_QUOTE 

An alias for KEY_APOSTROPHE, apostrophe/single-quote key.

KEY_EQUAL 

The equal/plus key.

KEY_COMMA 

The comma key.

KEY_MINUS 

The minus key.

KEY_PERIOD 

The period key.

KEY_SLASH 

The slash key.

KEY_GRAVE 

The grave key.

KEY_LBRACKET 

The left (square) bracket key e.g. [{.

KEY_PIPE 

The pipe/backslash key.

KEY_BACKSLASH 

An alias for the pipe/backslash key.

KEY_RBRACKET 

The right (square) bracket key e.g. ]}.

KEYS_MAX_KEYS 

Function Documentation

◆ input_get_mouse_position()

KAPI void input_get_mouse_position ( i32 x,
i32 y 
)

Obtains the current mouse position.

Parameters
xA pointer to hold the current mouse position on the x-axis.
yA pointer to hold the current mouse position on the y-axis.

◆ input_get_previous_mouse_position()

KAPI void input_get_previous_mouse_position ( i32 x,
i32 y 
)

Obtains the previous mouse position.

Parameters
xA pointer to hold the previous mouse position on the x-axis.
yA pointer to hold the previous mouse position on the y-axis.

◆ input_is_button_down()

KAPI b8 input_is_button_down ( buttons  button)

Indicates if the given mouse button is currently pressed.

Parameters
buttonThe button to check.
Returns
True if currently pressed; otherwise false.

◆ input_is_button_dragging()

KAPI b8 input_is_button_dragging ( buttons  button)

Indicates if the mouse is currently being dragged with the provided button being held down.

Parameters
buttonThe button to check.
Returns
True if dragging; otherwise false.

◆ input_is_button_up()

KAPI b8 input_is_button_up ( buttons  button)

Indicates if the given mouse button is currently released.

Parameters
buttonThe button to check.
Returns
True if currently released; otherwise false.

◆ input_is_key_down()

KAPI b8 input_is_key_down ( keys  key)

Indicates if the given key is currently pressed down.

Parameters
keyThey key to be checked.
Returns
True if currently pressed; otherwise false.

◆ input_is_key_up()

KAPI b8 input_is_key_up ( keys  key)

Indicates if the given key is NOT currently pressed down.

Parameters
keyThey key to be checked.
Returns
True if currently released; otherwise false.

◆ input_keycode_str()

KAPI const char* input_keycode_str ( keys  key)

Returns a string representation of the provided key. Ex. "tab" for the tab key.

Parameters
key
Returns
const char*

◆ input_keymap_pop()

KAPI b8 input_keymap_pop ( void  )

Attempts to pop the top-most keymap from the stack, if there is one.

Returns
True if a keymap was popped; otherwise false.

◆ input_keymap_push()

KAPI void input_keymap_push ( const struct keymap map)

Pushes a new keymap onto the keymap stack, making it the active keymap. A copy of the keymap is taken when pushing onto the stack.

Parameters
mapA constant pointer to the keymap to be pushed.

◆ input_process_button()

void input_process_button ( buttons  button,
b8  pressed 
)

Sets the press state of the given mouse button.

Parameters
buttonThe mouse button whose state to set.
pressedIndicates if the mouse button is currently pressed.

◆ input_process_key()

void input_process_key ( keys  key,
b8  pressed 
)

Sets the state for the given key.

Parameters
keyThe key to be processed.
pressedIndicates whether the key is currently pressed.

◆ input_process_mouse_move()

void input_process_mouse_move ( i16  x,
i16  y 
)

Sets the current position of the mouse to the given x and y positions. Also updates the previous position beforehand.

◆ input_process_mouse_wheel()

void input_process_mouse_wheel ( i8  z_delta)

Processes mouse wheel scrolling.

Parameters
z_deltaThe amount of scrolling which occurred on the z axis (mouse wheel)

◆ input_system_initialize()

b8 input_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the input system. Call twice; once to obtain memory requirement (passing state = 0), then a second time passing allocated memory to state.

Parameters
memory_requirementThe required size of the state memory.
stateEither 0 or the allocated block of state memory.
configIgnored.
Returns
True on success; otherwise false.

◆ input_system_shutdown()

void input_system_shutdown ( void *  state)

Shuts the input system down.

Parameters
stateA pointer to the system state.

◆ input_update()

void input_update ( const struct frame_data p_frame_data)

Updates the input system every frame.

Parameters
p_frame_dataA constant pointer to the current frame's data. NOTE: Does not use system manager update because it must be called at end of a frame.

◆ input_was_button_down()

KAPI b8 input_was_button_down ( buttons  button)

Indicates if the given mouse button was previously pressed in the last frame.

Parameters
buttonThe button to check.
Returns
True if previously pressed; otherwise false.

◆ input_was_button_up()

KAPI b8 input_was_button_up ( buttons  button)

Indicates if the given mouse button was previously released in the last frame.

Parameters
buttonThe button to check.
Returns
True if previously released; otherwise false.

◆ input_was_key_down()

KAPI b8 input_was_key_down ( keys  key)

Indicates if the given key was previously pressed down on the last frame.

Parameters
keyThey key to be checked.
Returns
True if was previously pressed; otherwise false.

◆ input_was_key_up()

KAPI b8 input_was_key_up ( keys  key)

Indicates if the given key was previously pressed down in the last frame.

Parameters
keyThey key to be checked.
Returns
True if previously released; otherwise false.