Loading...
Searching...
No Matches
keyboard.h File Reference
`#include <stdint.h>`

Go to the source code of this file.

## Macros

#define | ARC_KEYBOARD_BUTTON_NUM 239

## Typedefs

typedef struct ARC_Keyboard | ARC_Keyboard
typedef struct ARC_KeyboardInfo | ARC_KeyboardInfo
typedef enum ARC_KeyboardState | ARC_KeyboardState
typedef enum ARC_KeyboardKey | ARC_Keyboard_Key

## Enumerations

enum | ARC_KeyboardState { ARC_KEY_NONE , ARC_KEY_PRESSED , ARC_KEY_RELEASED }

enum

ARC_KeyboardKey {
ARC_KEY_A , ARC_KEY_B , ARC_KEY_C , ARC_KEY_D ,
ARC_KEY_E , ARC_KEY_F , ARC_KEY_G , ARC_KEY_H ,
ARC_KEY_I , ARC_KEY_J , ARC_KEY_K , ARC_KEY_L ,
ARC_KEY_M , ARC_KEY_N , ARC_KEY_O , ARC_KEY_P ,
ARC_KEY_Q , ARC_KEY_R , ARC_KEY_S , ARC_KEY_T ,
ARC_KEY_U , ARC_KEY_V , ARC_KEY_W , ARC_KEY_X ,
ARC_KEY_Y , ARC_KEY_Z , ARC_KEY_0 , ARC_KEY_1 ,
ARC_KEY_2 , ARC_KEY_3 , ARC_KEY_4 , ARC_KEY_5 ,
ARC_KEY_6 , ARC_KEY_7 , ARC_KEY_8 , ARC_KEY_9 ,
ARC_KEY_SPACE , ARC_KEY_ESC , ARC_KEY_ENTER
}

## Functions

void | ARC_Keyboard_CreateWithInput (ARC_Keyboard **keyboard, ARC_Input *input)
void | ARC_Keyboard_Destroy (ARC_Keyboard *keyboard)
void | ARC_Keyboard_Update (ARC_Keyboard *keyboard)
ARC_KeyboardState | ARC_Keyboard_GetState (ARC_Keyboard *keyboard, enum ARC_KeyboardKey key)

## Macro Definition Documentation

## ARC_KEYBOARD_BUTTON_NUM

#define ARC_KEYBOARD_BUTTON_NUM 239

Definition at line 25 of file keyboard.h.

Referenced by ARC_Keyboard_CreateWithInput().

## Typedef Documentation

## ARC_Keyboard

typedef struct ARC_Keyboard ARC_Keyboard

Definition at line 15 of file keyboard.h.

## ARC_Keyboard_Key

typedef enum ARC_KeyboardKey ARC_Keyboard_Key

## ARC_KeyboardInfo

typedef struct ARC_KeyboardInfo ARC_KeyboardInfo

Definition at line 17 of file keyboard.h.

## ARC_KeyboardState

typedef enum ARC_KeyboardState ARC_KeyboardState

## Enumeration Type Documentation

## ARC_KeyboardKey

enum ARC_KeyboardKey

Enumerator
ARC_KEY_A |
ARC_KEY_B |
ARC_KEY_C |
ARC_KEY_D |
ARC_KEY_E |
ARC_KEY_F |
ARC_KEY_G |
ARC_KEY_H |
ARC_KEY_I |
ARC_KEY_J |
ARC_KEY_K |
ARC_KEY_L |
ARC_KEY_M |
ARC_KEY_N |
ARC_KEY_O |
ARC_KEY_P |
ARC_KEY_Q |
ARC_KEY_R |
ARC_KEY_S |
ARC_KEY_T |
ARC_KEY_U |
ARC_KEY_V |
ARC_KEY_W |
ARC_KEY_X |
ARC_KEY_Y |
ARC_KEY_Z |
ARC_KEY_0 |
ARC_KEY_1 |
ARC_KEY_2 |
ARC_KEY_3 |
ARC_KEY_4 |
ARC_KEY_5 |
ARC_KEY_6 |
ARC_KEY_7 |
ARC_KEY_8 |
ARC_KEY_9 |
ARC_KEY_SPACE |
ARC_KEY_ESC |
ARC_KEY_ENTER |

Definition at line 32 of file keyboard.h.

{
ARC_KEY_A,
ARC_KEY_B,
ARC_KEY_C,
ARC_KEY_D,
ARC_KEY_E,
ARC_KEY_F,
ARC_KEY_G,
ARC_KEY_H,
ARC_KEY_I,
ARC_KEY_J,
ARC_KEY_K,
ARC_KEY_L,
ARC_KEY_M,
ARC_KEY_N,
ARC_KEY_O,
ARC_KEY_P,
ARC_KEY_Q,
ARC_KEY_R,
ARC_KEY_S,
ARC_KEY_T,
ARC_KEY_U,
ARC_KEY_V,
ARC_KEY_W,
ARC_KEY_X,
ARC_KEY_Y,
ARC_KEY_Z,
ARC_KEY_0,
ARC_KEY_1,
ARC_KEY_2,
ARC_KEY_3,
ARC_KEY_4,
ARC_KEY_5,
ARC_KEY_6,
ARC_KEY_7,
ARC_KEY_8,
ARC_KEY_9,
ARC_KEY_SPACE,
ARC_KEY_ESC,
ARC_KEY_ENTER,
} ARC_Keyboard_Key;
ARC_KEY_F
@ ARC_KEY_F
Definition keyboard.h:38
ARC_KEY_4
@ ARC_KEY_4
Definition keyboard.h:64
ARC_KEY_2
@ ARC_KEY_2
Definition keyboard.h:62
ARC_KEY_0
@ ARC_KEY_0
Definition keyboard.h:60
ARC_KEY_M
@ ARC_KEY_M
Definition keyboard.h:45
ARC_KEY_K
@ ARC_KEY_K
Definition keyboard.h:43
ARC_KEY_P
@ ARC_KEY_P
Definition keyboard.h:48
ARC_KEY_E
@ ARC_KEY_E
Definition keyboard.h:37
ARC_KEY_8
@ ARC_KEY_8
Definition keyboard.h:68
ARC_KEY_T
@ ARC_KEY_T
Definition keyboard.h:52
ARC_KEY_Z
@ ARC_KEY_Z
Definition keyboard.h:58
ARC_KEY_A
@ ARC_KEY_A
Definition keyboard.h:33
ARC_KEY_Y
@ ARC_KEY_Y
Definition keyboard.h:57
ARC_KEY_9
@ ARC_KEY_9
Definition keyboard.h:69
ARC_KEY_ESC
@ ARC_KEY_ESC
Definition keyboard.h:72
ARC_KEY_W
@ ARC_KEY_W
Definition keyboard.h:55
ARC_KEY_5
@ ARC_KEY_5
Definition keyboard.h:65
ARC_KEY_3
@ ARC_KEY_3
Definition keyboard.h:63
ARC_KEY_J
@ ARC_KEY_J
Definition keyboard.h:42
ARC_KEY_N
@ ARC_KEY_N
Definition keyboard.h:46
ARC_KEY_O
@ ARC_KEY_O
Definition keyboard.h:47
ARC_KEY_L
@ ARC_KEY_L
Definition keyboard.h:44
ARC_KEY_R
@ ARC_KEY_R
Definition keyboard.h:50
ARC_KEY_C
@ ARC_KEY_C
Definition keyboard.h:35
ARC_KEY_6
@ ARC_KEY_6
Definition keyboard.h:66
ARC_KEY_X
@ ARC_KEY_X
Definition keyboard.h:56
ARC_KEY_I
@ ARC_KEY_I
Definition keyboard.h:41
ARC_KEY_1
@ ARC_KEY_1
Definition keyboard.h:61
ARC_KEY_7
@ ARC_KEY_7
Definition keyboard.h:67
ARC_KEY_ENTER
@ ARC_KEY_ENTER
Definition keyboard.h:73
ARC_KEY_Q
@ ARC_KEY_Q
Definition keyboard.h:49
ARC_KEY_SPACE
@ ARC_KEY_SPACE
Definition keyboard.h:71
ARC_KEY_U
@ ARC_KEY_U
Definition keyboard.h:53
ARC_KEY_V
@ ARC_KEY_V
Definition keyboard.h:54
ARC_KEY_B
@ ARC_KEY_B
Definition keyboard.h:34
ARC_KEY_D
@ ARC_KEY_D
Definition keyboard.h:36
ARC_KEY_G
@ ARC_KEY_G
Definition keyboard.h:39
ARC_KEY_S
@ ARC_KEY_S
Definition keyboard.h:51
ARC_KEY_H
@ ARC_KEY_H
Definition keyboard.h:40
ARC_Keyboard_Key
enum ARC_KeyboardKey ARC_Keyboard_Key

## ARC_KeyboardState

enum ARC_KeyboardState

Enumerator
ARC_KEY_NONE |
ARC_KEY_PRESSED |
ARC_KEY_RELEASED |

Definition at line 19 of file keyboard.h.

{
ARC_KEY_NONE,
ARC_KEY_PRESSED,
ARC_KEY_RELEASED
} ARC_KeyboardState;
ARC_KeyboardState
ARC_KeyboardState
Definition keyboard.h:19
ARC_KEY_RELEASED
@ ARC_KEY_RELEASED
Definition keyboard.h:22
ARC_KEY_PRESSED
@ ARC_KEY_PRESSED
Definition keyboard.h:21
ARC_KEY_NONE
@ ARC_KEY_NONE
Definition keyboard.h:20

## Function Documentation

## ARC_Keyboard_CreateWithInput()

void ARC_Keyboard_CreateWithInput | ( | ARC_Keyboard ** | keyboard,
|  | ARC_Input * | input )

Definition at line 11 of file keyboard.c.

{
*keyboard = (ARC_Keyboard *)malloc(sizeof(ARC_Keyboard));
(*keyboard)->event = input->event;
(*keyboard)->keys = (ARC_KeyboardState *)malloc(sizeof(ARC_KeyboardState) * ARC_KEYBOARD_BUTTON_NUM);
(*keyboard)->released = NULL;
for(uint8_t i = 0; i < ARC_KEYBOARD_BUTTON_NUM; i++){
(*keyboard)->keys[i] = ARC_KEY_NONE;
}
}
ARC_KEYBOARD_BUTTON_NUM
#define ARC_KEYBOARD_BUTTON_NUM
Definition keyboard.h:25
ARC_Input::event
SDL_Event * event
Definition input.h:12
ARC_Keyboard
Definition keyboard.h:7
ARC_Keyboard::event
SDL_Event * event
Definition keyboard.h:8

References ARC_KEY_NONE, ARC_KEYBOARD_BUTTON_NUM, ARC_Input::event, and ARC_Keyboard::event.

Referenced by ARC_Input_CreateWithEngineData().

## ARC_Keyboard_Destroy()

void ARC_Keyboard_Destroy | ( | ARC_Keyboard * | keyboard | ) |

Definition at line 23 of file keyboard.c.

{
free(keyboard->keys);
free(keyboard);
}
ARC_Keyboard::keys
ARC_KeyboardState * keys
Definition keyboard.h:10

References ARC_Keyboard::keys.

Referenced by ARC_EngineData_Destroy(), and ARC_Input_Destroy().

## ARC_Keyboard_GetState()

ARC_KeyboardState ARC_Keyboard_GetState | ( | ARC_Keyboard * | keyboard,
|  | enum ARC_KeyboardKey | key )

Definition at line 52 of file keyboard.c.

{
switch(key){
case ARC_KEY_A: return keyboard->keys[SDLK_a];
case ARC_KEY_B: return keyboard->keys[SDLK_b];
case ARC_KEY_C: return keyboard->keys[SDLK_c];
case ARC_KEY_D: return keyboard->keys[SDLK_d];
case ARC_KEY_E: return keyboard->keys[SDLK_e];
case ARC_KEY_F: return keyboard->keys[SDLK_f];
case ARC_KEY_G: return keyboard->keys[SDLK_g];
case ARC_KEY_H: return keyboard->keys[SDLK_h];
case ARC_KEY_I: return keyboard->keys[SDLK_i];
case ARC_KEY_J: return keyboard->keys[SDLK_j];
case ARC_KEY_K: return keyboard->keys[SDLK_k];
case ARC_KEY_L: return keyboard->keys[SDLK_l];
case ARC_KEY_M: return keyboard->keys[SDLK_m];
case ARC_KEY_N: return keyboard->keys[SDLK_n];
case ARC_KEY_O: return keyboard->keys[SDLK_o];
case ARC_KEY_P: return keyboard->keys[SDLK_p];
case ARC_KEY_Q: return keyboard->keys[SDLK_q];
case ARC_KEY_R: return keyboard->keys[SDLK_r];
case ARC_KEY_S: return keyboard->keys[SDLK_s];
case ARC_KEY_T: return keyboard->keys[SDLK_t];
case ARC_KEY_U: return keyboard->keys[SDLK_u];
case ARC_KEY_V: return keyboard->keys[SDLK_v];
case ARC_KEY_W: return keyboard->keys[SDLK_w];
case ARC_KEY_X: return keyboard->keys[SDLK_x];
case ARC_KEY_Y: return keyboard->keys[SDLK_y];
case ARC_KEY_Z: return keyboard->keys[SDLK_z];
case ARC_KEY_0: return keyboard->keys[SDLK_0];
case ARC_KEY_1: return keyboard->keys[SDLK_1];
case ARC_KEY_2: return keyboard->keys[SDLK_2];
case ARC_KEY_3: return keyboard->keys[SDLK_3];
case ARC_KEY_4: return keyboard->keys[SDLK_4];
case ARC_KEY_5: return keyboard->keys[SDLK_5];
case ARC_KEY_6: return keyboard->keys[SDLK_6];
case ARC_KEY_7: return keyboard->keys[SDLK_7];
case ARC_KEY_8: return keyboard->keys[SDLK_8];
case ARC_KEY_9: return keyboard->keys[SDLK_9];
case ARC_KEY_SPACE: return keyboard->keys[SDLK_SPACE ];
case ARC_KEY_ESC: return keyboard->keys[SDLK_ESCAPE];
case ARC_KEY_ENTER: return keyboard->keys[SDLK_RETURN];
default: return ARC_KEY_NONE;
}
}

References ARC_KEY_0, ARC_KEY_1, ARC_KEY_2, ARC_KEY_3, ARC_KEY_4, ARC_KEY_5, ARC_KEY_6, ARC_KEY_7, ARC_KEY_8, ARC_KEY_9, ARC_KEY_A, ARC_KEY_B, ARC_KEY_C, ARC_KEY_D, ARC_KEY_E, ARC_KEY_ENTER, ARC_KEY_ESC, ARC_KEY_F, ARC_KEY_G, ARC_KEY_H, ARC_KEY_I, ARC_KEY_J, ARC_KEY_K, ARC_KEY_L, ARC_KEY_M, ARC_KEY_N, ARC_KEY_NONE, ARC_KEY_O, ARC_KEY_P, ARC_KEY_Q, ARC_KEY_R, ARC_KEY_S, ARC_KEY_SPACE, ARC_KEY_T, ARC_KEY_U, ARC_KEY_V, ARC_KEY_W, ARC_KEY_X, ARC_KEY_Y, ARC_KEY_Z, and ARC_Keyboard::keys.

## ARC_Keyboard_Update()

void ARC_Keyboard_Update | ( | ARC_Keyboard * | keyboard | ) |

Definition at line 29 of file keyboard.c.

{
if(keyboard->released){
*keyboard->released = ARC_KEY_NONE;
keyboard->released = NULL;
}
if(keyboard->event->type != SDL_KEYDOWN && keyboard->event->type != SDL_KEYUP){
return;
}
if(keyboard->event->key.keysym.sym >= 239 || keyboard->event->key.keysym.sym < 0){
return;
}
if(keyboard->event->type == SDL_KEYDOWN){
keyboard->keys[keyboard->event->key.keysym.sym] = ARC_KEY_PRESSED;
return;
}
keyboard->keys[keyboard->event->key.keysym.sym] = ARC_KEY_RELEASED;
keyboard->released = (keyboard->keys + keyboard->event->key.keysym.sym);
}
ARC_Keyboard::released
ARC_KeyboardState * released
Definition keyboard.h:11

References ARC_KEY_NONE, ARC_KEY_PRESSED, ARC_KEY_RELEASED, ARC_Keyboard::event, ARC_Keyboard::keys, and ARC_Keyboard::released.

Referenced by ARC_Input_Update().