From 939693159204124bc5f7caa5fb3d9af20d5fdd40 Mon Sep 17 00:00:00 2001 From: Ry Date: Thu, 27 Oct 2022 16:01:51 -0700 Subject: [PATCH] Better keyboard handling --- src/keyboard.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 6fdb21a..a845590 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -95,6 +95,7 @@ static const keycode_t key_map[SDL_NUM_SCANCODES] = { [SDL_SCANCODE_LEFTBRACKET] = 0x1A, [SDL_SCANCODE_RIGHTBRACKET] = 0x1B, [SDL_SCANCODE_RETURN] = 0x1C, + [SDL_SCANCODE_KP_ENTER] = 0x1C, [SDL_SCANCODE_LCTRL] = 0x1D, [SDL_SCANCODE_A] = 0x1E, [SDL_SCANCODE_S] = 0x1F, @@ -144,14 +145,16 @@ static const keycode_t key_map[SDL_NUM_SCANCODES] = { }; keycode_t key_convert(int sdlcode) { - if (sdlcode < 0 || sdlcode > SDL_NUM_SCANCODES) abort(); + if (sdlcode < 0 || sdlcode > SDL_NUM_SCANCODES) return 0; return key_map[sdlcode]; } void key_pressed(int sdlcode) { - key_put(key_convert(sdlcode)); + keycode_t code = key_convert(sdlcode); + if (code) key_put(code); } void key_released(int sdlcode) { - key_put(key_convert(sdlcode) | 0x80); + keycode_t code = key_convert(sdlcode) | 0x80; + if (code) key_put(code); }