From be831308207bfa056f900a094a9ce71e976e5b3d Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 12 Jul 2015 18:22:30 +0200 Subject: [PATCH] Simple keyboard support for SDL --- src/sdl.c | 14 +++++++++++++- src/sdl.h | 28 ++++++++++++++++++++++++++++ src/video/sdl.c | 3 --- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/sdl.c b/src/sdl.c index 606eb49..390e243 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -19,6 +19,8 @@ #ifdef HAVE_SDL +#include "sdl.h" + #include "limelight-common/Limelight.h" #include @@ -56,9 +58,19 @@ void sdl_loop() { } if (button != 0) - LiSendMouseButtonEvent(event.button.state==SDL_PRESSED?BUTTON_ACTION_PRESS:BUTTON_ACTION_RELEASE, button); + LiSendMouseButtonEvent(event.type==SDL_MOUSEBUTTONDOWN?BUTTON_ACTION_PRESS:BUTTON_ACTION_RELEASE, button); break; + case SDL_KEYDOWN: + case SDL_KEYUP: + button = event.key.keysym.sym; + if (button >= (0x40000000 + 0x39) && button < (0x40000000 + sizeof(keyCodes))) + button = keyCodes[button - 0x40000039]; + if (button >= 0x61) + button -= 0x20; + + LiSendKeyboardEvent(0x80 << 8 | button, event.type==SDL_KEYDOWN?KEY_ACTION_DOWN:KEY_ACTION_UP, 0); + break; case SDL_QUIT: done = true; } diff --git a/src/sdl.h b/src/sdl.h index 477bacf..010a750 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -19,6 +19,34 @@ #ifdef HAVE_SDL +static const short keyCodes[] = { + 0x14, //SDLK_CAPSLOCK + 0x70, //SDLK_F1 + 0x71, //SDLK_F2 + 0x72, //SDLK_F3 + 0x73, //SDLK_F4 + 0x74, //SDLK_F5 + 0x75, //SDLK_F6 + 0x76, //SDLK_F7 + 0x77, //SDLK_F8 + 0x78, //SDLK_F9 + 0x79, //SDLK_F10 + 0x7A, //SDLK_F11 + 0x7B, //SDLK_F12 + 0, //SDLK_PRINTSCREEN + 0x91, //SDLK_SCROLLLOCK + 0x13, //SDLK_PAUSE + 0x9B, //SDLK_INSERT + 0x24, //SDLK_HOME + 0x21, //SDLK_PAGEUP + 0x23, //SDLK_END + 0x22, //SDLK_PAGEDOWN + 0x27, //SDLK_RIGHT + 0x25, //SDLK_LEFT + 0x28, //SDLK_DOWN + 0x26, //SDLK_UP +}; + void sdl_loop(); #endif /* HAVE_SDL */ diff --git a/src/video/sdl.c b/src/video/sdl.c index b33b711..d2c82d5 100644 --- a/src/video/sdl.c +++ b/src/video/sdl.c @@ -101,9 +101,6 @@ static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) { fprintf(stderr, "Video decode buffer too small"); exit(1); } - - SDL_Event event; - SDL_PollEvent(&event); return DR_OK; }