aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_events.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_key_events.c')
-rw-r--r--src/ft_key_events.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 267bccf..54f3033 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -15,25 +15,15 @@
#include <stdlib.h>
#include <stdint.h>
-static uint16_t
- ft_set_keycode(const uint16_t tmp_code)
+static void
+ ft_insert_key(uint16_t keycode, t_cub *clist)
{
- uint16_t keycode;
+ uint8_t i;
- keycode = UINT16_MAX;
- (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
- (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
- (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
- (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
- (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
- (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
- (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
- (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
- (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
- return (keycode);
+ i = 0;
+ while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1)
+ i++;
+ clist->key_input[i] = keycode;
}
static void
@@ -53,7 +43,7 @@ int
ft_key_event(int keycode, t_cub *clist)
{
int (*fun_ptr[6])(t_cub*);
- const uint16_t tmp_code = keycode;
+ const int32_t tmp_code = keycode;
const float old_y = clist->plist->pos_y;
const float old_x = clist->plist->pos_x;
@@ -63,7 +53,14 @@ int
fun_ptr[3] = ft_d_key;
fun_ptr[4] = ft_left_key;
fun_ptr[5] = ft_right_key;
- keycode = ft_set_keycode(tmp_code);
+ keycode = ft_convert_keycode(tmp_code);
+ ft_insert_key(keycode, clist);
+ ft_printf("keys [%d][%d][%d][%d][%d]\n",
+ clist->key_input[0],
+ clist->key_input[1],
+ clist->key_input[2],
+ clist->key_input[3],
+ clist->key_input[4]);
if (keycode <= 5)
{
(*fun_ptr[keycode])(clist);