/* ************************************************************************** */ /* LE - / */ /* / */ /* ft_key_events.c .:: .:/ . .:: */ /* +:+:+ +: +: +:+:+ */ /* By: rbousset +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2020/02/02 17:19:30 by rbousset #+# ## ## #+# */ /* Updated: 2020/02/02 17:19:30 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ #include #include #include static int ft_w_key(void) { ft_printf("[W]\n"); return (0); } static int ft_a_key(void) { ft_printf("[A]\n"); return (0); } static int ft_s_key(void) { ft_printf("[S]\n"); return (0); } static int ft_d_key(void) { ft_printf("[D]\n"); return (0); } int ft_key_event(int keycode, void *param) { int (*fun_ptr[4])(void); fun_ptr[0] = ft_w_key; fun_ptr[1] = ft_a_key; fun_ptr[2] = ft_s_key; fun_ptr[3] = ft_d_key; ft_printf("Key [%d] pressed\n", keycode); (keycode == FT_W_KEY) ? (keycode = 0) : 0; (keycode == FT_A_KEY) ? (keycode = 1) : 0; (keycode == FT_S_KEY) ? (keycode = 2) : 0; (keycode == FT_D_KEY) ? (keycode = 3) : 0; (keycode <= 3) ? ((*fun_ptr[keycode])()) : 0; if (keycode == FT_ESC_KEY) ft_exit(0, ((t_cub*)param)); return (0); }