Loading...
Searching...
No Matches
key.c
Go to the documentation of this file.
#include "arc/console/key.h"
#include "key.h"
#include "arc/std/bool.h"
#include <ncurses.h>
#include <stdlib.h>
void ARC_ConsoleKey_Create(ARC_ConsoleKey **consoleKey, ARC_ConsoleKey_Key *key){
*consoleKey = (ARC_ConsoleKey *)malloc(sizeof(ARC_ConsoleKey));
(*consoleKey)->key = 0;
if(key != NULL){
(*consoleKey)->key = *key;
}
}
void ARC_ConsoleKey_Destroy(ARC_ConsoleKey *consoleKey){
free(consoleKey);
}
ARC_Bool ARC_ConsoleKey_Equals(ARC_ConsoleKey consoleKey, ARC_ConsoleKey_Key key){
return consoleKey.key == ARC_Keyboard_GetConsoleKey(key).key;
}
ARC_Bool ARC_ConsoleKey_EqualsPointer(ARC_ConsoleKey *consoleKey, ARC_ConsoleKey_Key key){
return consoleKey->key == ARC_Keyboard_GetConsoleKey(key).key;
}
ARC_ConsoleKey ARC_Keyboard_GetConsoleKey(enum ARC_ConsoleKey_Key key){
switch(key){
case ARC_CONSOLE_KEY_A:
return (ARC_ConsoleKey){ (int32_t)'a' };
case ARC_CONSOLE_KEY_B:
return (ARC_ConsoleKey){ (int32_t)'b' };
case ARC_CONSOLE_KEY_C:
return (ARC_ConsoleKey){ (int32_t)'c' };
case ARC_CONSOLE_KEY_D:
return (ARC_ConsoleKey){ (int32_t)'d' };
case ARC_CONSOLE_KEY_E:
return (ARC_ConsoleKey){ (int32_t)'e' };
case ARC_CONSOLE_KEY_F:
return (ARC_ConsoleKey){ (int32_t)'f' };
case ARC_CONSOLE_KEY_G:
return (ARC_ConsoleKey){ (int32_t)'g' };
case ARC_CONSOLE_KEY_H:
return (ARC_ConsoleKey){ (int32_t)'h' };
case ARC_CONSOLE_KEY_I:
return (ARC_ConsoleKey){ (int32_t)'i' };
case ARC_CONSOLE_KEY_J:
return (ARC_ConsoleKey){ (int32_t)'j' };
case ARC_CONSOLE_KEY_K:
return (ARC_ConsoleKey){ (int32_t)'k' };
case ARC_CONSOLE_KEY_L:
return (ARC_ConsoleKey){ (int32_t)'l' };
case ARC_CONSOLE_KEY_M:
return (ARC_ConsoleKey){ (int32_t)'m' };
case ARC_CONSOLE_KEY_N:
return (ARC_ConsoleKey){ (int32_t)'n' };
case ARC_CONSOLE_KEY_O:
return (ARC_ConsoleKey){ (int32_t)'o' };
case ARC_CONSOLE_KEY_P:
return (ARC_ConsoleKey){ (int32_t)'p' };
case ARC_CONSOLE_KEY_Q:
return (ARC_ConsoleKey){ (int32_t)'q' };
case ARC_CONSOLE_KEY_R:
return (ARC_ConsoleKey){ (int32_t)'r' };
case ARC_CONSOLE_KEY_S:
return (ARC_ConsoleKey){ (int32_t)'s' };
case ARC_CONSOLE_KEY_T:
return (ARC_ConsoleKey){ (int32_t)'t' };
case ARC_CONSOLE_KEY_U:
return (ARC_ConsoleKey){ (int32_t)'u' };
case ARC_CONSOLE_KEY_V:
return (ARC_ConsoleKey){ (int32_t)'v' };
case ARC_CONSOLE_KEY_W:
return (ARC_ConsoleKey){ (int32_t)'w' };
case ARC_CONSOLE_KEY_X:
return (ARC_ConsoleKey){ (int32_t)'x' };
case ARC_CONSOLE_KEY_Y:
return (ARC_ConsoleKey){ (int32_t)'y' };
case ARC_CONSOLE_KEY_Z:
return (ARC_ConsoleKey){ (int32_t)'z' };
case ARC_CONSOLE_KEY_0:
return (ARC_ConsoleKey){ (int32_t)'0' };
case ARC_CONSOLE_KEY_1:
return (ARC_ConsoleKey){ (int32_t)'1' };
case ARC_CONSOLE_KEY_2:
return (ARC_ConsoleKey){ (int32_t)'2' };
case ARC_CONSOLE_KEY_3:
return (ARC_ConsoleKey){ (int32_t)'3' };
case ARC_CONSOLE_KEY_4:
return (ARC_ConsoleKey){ (int32_t)'4' };
case ARC_CONSOLE_KEY_5:
return (ARC_ConsoleKey){ (int32_t)'5' };
case ARC_CONSOLE_KEY_6:
return (ARC_ConsoleKey){ (int32_t)'6' };
case ARC_CONSOLE_KEY_7:
return (ARC_ConsoleKey){ (int32_t)'7' };
case ARC_CONSOLE_KEY_8:
return (ARC_ConsoleKey){ (int32_t)'8' };
case ARC_CONSOLE_KEY_9:
return (ARC_ConsoleKey){ (int32_t)'9' };
case ARC_CONSOLE_KEY_UP:
return (ARC_ConsoleKey){ KEY_UP };
case ARC_CONSOLE_KEY_DOWN:
return (ARC_ConsoleKey){ KEY_DOWN };
case ARC_CONSOLE_KEY_LEFT:
return (ARC_ConsoleKey){ KEY_LEFT };
case ARC_CONSOLE_KEY_RIGHT:
return (ARC_ConsoleKey){ KEY_RIGHT };
case ARC_CONSOLE_KEY_FORWARD_SLASH:
return (ARC_ConsoleKey){ (int32_t)'/' };
case ARC_CONSOLE_KEY_BACKSPACE:
return (ARC_ConsoleKey){ KEY_BACKSPACE };
//TODO: This should probs be KEY_ENTER, but idk why it wasn't working
case ARC_CONSOLE_KEY_ENTER:
return (ARC_ConsoleKey){ 10 };
//TODO: This is escape and alt, need to fix
case ARC_CONSOLE_KEY_ESC:
return (ARC_ConsoleKey){ 27 };
default:
return (ARC_ConsoleKey){ 0 };
}
}
uint8_t ARC_ConsoleKey_GetCharFromKey(ARC_ConsoleKey *consoleKey){
return consoleKey->key;
}
bool.h
ARC_Bool
#define ARC_Bool
Definition bool.h:10
key.h
ARC_ConsoleKey_Key
ARC_ConsoleKey_Key
Definition key.h:13
ARC_CONSOLE_KEY_K
@ ARC_CONSOLE_KEY_K
Definition key.h:24
ARC_CONSOLE_KEY_8
@ ARC_CONSOLE_KEY_8
Definition key.h:49
ARC_CONSOLE_KEY_L
@ ARC_CONSOLE_KEY_L
Definition key.h:25
ARC_CONSOLE_KEY_B
@ ARC_CONSOLE_KEY_B
Definition key.h:15
ARC_CONSOLE_KEY_X
@ ARC_CONSOLE_KEY_X
Definition key.h:37
ARC_CONSOLE_KEY_7
@ ARC_CONSOLE_KEY_7
Definition key.h:48
ARC_CONSOLE_KEY_Z
@ ARC_CONSOLE_KEY_Z
Definition key.h:39
ARC_CONSOLE_KEY_UP
@ ARC_CONSOLE_KEY_UP
Definition key.h:55
ARC_CONSOLE_KEY_S
@ ARC_CONSOLE_KEY_S
Definition key.h:32
ARC_CONSOLE_KEY_D
@ ARC_CONSOLE_KEY_D
Definition key.h:17
ARC_CONSOLE_KEY_FORWARD_SLASH
@ ARC_CONSOLE_KEY_FORWARD_SLASH
Definition key.h:57
ARC_CONSOLE_KEY_C
@ ARC_CONSOLE_KEY_C
Definition key.h:16
ARC_CONSOLE_KEY_DOWN
@ ARC_CONSOLE_KEY_DOWN
Definition key.h:54
ARC_CONSOLE_KEY_1
@ ARC_CONSOLE_KEY_1
Definition key.h:42
ARC_CONSOLE_KEY_T
@ ARC_CONSOLE_KEY_T
Definition key.h:33
ARC_CONSOLE_KEY_P
@ ARC_CONSOLE_KEY_P
Definition key.h:29
ARC_CONSOLE_KEY_2
@ ARC_CONSOLE_KEY_2
Definition key.h:43
ARC_CONSOLE_KEY_3
@ ARC_CONSOLE_KEY_3
Definition key.h:44
ARC_CONSOLE_KEY_LEFT
@ ARC_CONSOLE_KEY_LEFT
Definition key.h:52
ARC_CONSOLE_KEY_V
@ ARC_CONSOLE_KEY_V
Definition key.h:35
ARC_CONSOLE_KEY_U
@ ARC_CONSOLE_KEY_U
Definition key.h:34
ARC_CONSOLE_KEY_J
@ ARC_CONSOLE_KEY_J
Definition key.h:23
ARC_CONSOLE_KEY_4
@ ARC_CONSOLE_KEY_4
Definition key.h:45
ARC_CONSOLE_KEY_H
@ ARC_CONSOLE_KEY_H
Definition key.h:21
ARC_CONSOLE_KEY_I
@ ARC_CONSOLE_KEY_I
Definition key.h:22
ARC_CONSOLE_KEY_M
@ ARC_CONSOLE_KEY_M
Definition key.h:26
ARC_CONSOLE_KEY_A
@ ARC_CONSOLE_KEY_A
Definition key.h:14
ARC_CONSOLE_KEY_G
@ ARC_CONSOLE_KEY_G
Definition key.h:20
ARC_CONSOLE_KEY_R
@ ARC_CONSOLE_KEY_R
Definition key.h:31
ARC_CONSOLE_KEY_F
@ ARC_CONSOLE_KEY_F
Definition key.h:19
ARC_CONSOLE_KEY_6
@ ARC_CONSOLE_KEY_6
Definition key.h:47
ARC_CONSOLE_KEY_N
@ ARC_CONSOLE_KEY_N
Definition key.h:27
ARC_CONSOLE_KEY_9
@ ARC_CONSOLE_KEY_9
Definition key.h:50
ARC_CONSOLE_KEY_ENTER
@ ARC_CONSOLE_KEY_ENTER
Definition key.h:61
ARC_CONSOLE_KEY_W
@ ARC_CONSOLE_KEY_W
Definition key.h:36
ARC_CONSOLE_KEY_5
@ ARC_CONSOLE_KEY_5
Definition key.h:46
ARC_CONSOLE_KEY_Y
@ ARC_CONSOLE_KEY_Y
Definition key.h:38
ARC_CONSOLE_KEY_RIGHT
@ ARC_CONSOLE_KEY_RIGHT
Definition key.h:53
ARC_CONSOLE_KEY_0
@ ARC_CONSOLE_KEY_0
Definition key.h:41
ARC_CONSOLE_KEY_BACKSPACE
@ ARC_CONSOLE_KEY_BACKSPACE
Definition key.h:59
ARC_CONSOLE_KEY_Q
@ ARC_CONSOLE_KEY_Q
Definition key.h:30
ARC_CONSOLE_KEY_O
@ ARC_CONSOLE_KEY_O
Definition key.h:28
ARC_CONSOLE_KEY_E
@ ARC_CONSOLE_KEY_E
Definition key.h:18
ARC_CONSOLE_KEY_ESC
@ ARC_CONSOLE_KEY_ESC
Definition key.h:63
ARC_ConsoleKey_Equals
ARC_Bool ARC_ConsoleKey_Equals(ARC_ConsoleKey consoleKey, ARC_ConsoleKey_Key key)
Definition key.c:20
ARC_Keyboard_GetConsoleKey
ARC_ConsoleKey ARC_Keyboard_GetConsoleKey(enum ARC_ConsoleKey_Key key)
Definition key.c:28
ARC_ConsoleKey_EqualsPointer
ARC_Bool ARC_ConsoleKey_EqualsPointer(ARC_ConsoleKey *consoleKey, ARC_ConsoleKey_Key key)
Definition key.c:24
ARC_ConsoleKey_Create
void ARC_ConsoleKey_Create(ARC_ConsoleKey **consoleKey, ARC_ConsoleKey_Key *key)
Definition key.c:7
ARC_ConsoleKey_GetCharFromKey
uint8_t ARC_ConsoleKey_GetCharFromKey(ARC_ConsoleKey *consoleKey)
Definition key.c:169
ARC_ConsoleKey_Destroy
void ARC_ConsoleKey_Destroy(ARC_ConsoleKey *consoleKey)
Definition key.c:16
key.h
ARC_ConsoleKeyType
Definition key.h:11
ARC_ConsoleKeyType::key
int32_t key
Definition key.h:12