1 #include <lib/base/etrace.h>
2 #include <lib/driver/rcsdl.h>
3 //#include <lib/actions/action.h>
4 #include <lib/base/init.h>
5 #include <lib/base/init_num.h>
6 #include <lib/driver/input_fake.h>
12 eSDLInputDevice::eSDLInputDevice(eRCDriver *driver) : eRCDevice("SDL", driver), m_escape(false), m_unicode(0)
16 eSDLInputDevice::~eSDLInputDevice()
20 void eSDLInputDevice::handleCode(long arg)
24 const SDL_KeyboardEvent *event = (const SDL_KeyboardEvent *)arg;
25 const SDL_keysym *key = &event->keysym;
26 int km = input->getKeyboardMode();
29 if (event->type == SDL_KEYDOWN) {
30 m_unicode = key->unicode;
31 flags = eRCKey::flagMake;
33 flags = eRCKey::flagBreak;
36 if (km == eRCInput::kmNone) {
37 code = translateKey(key->sym);
38 D_PRINT("translated code: %d", code);
41 D_PRINT("native virtual code: %d / sym: %d", code, key->sym);
42 if ((code == 0) && (key->sym < 128)) {
44 D_PRINT("ASCII code: %u", code);
47 if ((km == eRCInput::kmAscii) &&
48 ((code < SDLK_SPACE) ||
50 (code == SDLK_DELETE) ||
52 code = translateKey(key->sym);
54 // ASCII keys should only generate key press events
55 if (flags == eRCKey::flagBreak)
58 if (km == eRCInput::kmAscii) {
59 // skip ESC c or ESC '[' c
65 if (code == SDLK_ESCAPE)
68 flags |= eRCKey::flagAscii;
72 D_PRINT("code=%d (%#x) flags=%d (%#x)", code, code, flags, flags);
73 input->keyPressed(eRCKey(this, code, flags));
77 const char *eSDLInputDevice::getDescription() const
82 int eSDLInputDevice::translateKey(SDLKey key)
84 #define P(a) case SDLK_##a: return KEY_##a
85 #define P2(a,b) case SDLK_##a: return KEY_##b
104 P2(QUOTE,APOSTROPHE);
140 P2(LEFTBRACKET,LEFTBRACE);
142 P2(RIGHTBRACKET,RIGHTBRACE);
284 P2(KP_DIVIDE,KPSLASH);
285 P2(KP_MULTIPLY,KPASTERISK);
286 P2(KP_MINUS,KPMINUS);
288 P2(KP_ENTER,KPENTER);
289 P2(KP_EQUALS,KPEQUAL);
316 P2(SCROLLOCK,SCROLLLOCK);
317 P2(RSHIFT,RIGHTSHIFT);
318 P2(LSHIFT,LEFTSHIFT);
340 eDebug("unhandled SDL keycode: %d", key);
352 eSDLInputDriver *eSDLInputDriver::instance;
354 eSDLInputDriver::eSDLInputDriver() : eRCDriver(eRCInput::getInstance())
356 ASSERT(instance == 0);
360 eSDLInputDriver::~eSDLInputDriver()
365 void eSDLInputDriver::keyPressed(const SDL_KeyboardEvent *key)
367 eDebug("km=%d enabled=%d locked=%d",
368 input->getKeyboardMode(), enabled, input->islocked());
370 if (!enabled || input->islocked())
373 std::list<eRCDevice*>::iterator i(listeners.begin());
374 while (i != listeners.end()) {
375 (*i)->handleCode((long)key);
383 eSDLInputDriver driver;
384 eSDLInputDevice device;
387 eRCSDLInit(): driver(), device(&driver)
392 eAutoInitP0<eRCSDLInit> init_rcSDL(eAutoInitNumbers::rc+1, "SDL RC Driver");