1 #include <lib/driver/rcsdl.h>
2 //#include <lib/actions/action.h>
3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
5 #include <lib/driver/input_fake.h>
11 eSDLInputDevice::eSDLInputDevice(eRCDriver *driver) : eRCDevice("SDL", driver), m_escape(false), m_unicode(0)
15 eSDLInputDevice::~eSDLInputDevice()
19 void eSDLInputDevice::handleCode(long arg)
21 const SDL_KeyboardEvent *event = (const SDL_KeyboardEvent *)arg;
22 const SDL_keysym *key = &event->keysym;
23 int km = input->getKeyboardMode();
26 if (event->type == SDL_KEYDOWN) {
27 m_unicode = key->unicode;
28 flags = eRCKey::flagMake;
30 flags = eRCKey::flagBreak;
33 if (km == eRCInput::kmNone) {
34 code = translateKey(key->sym);
36 eDebug("unicode=%04x scancode=%02x", m_unicode, key->scancode);
37 if (m_unicode & 0xff80) {
38 eDebug("SDL: skipping unicode character");
41 code = m_unicode & ~0xff80;
42 // unicode not set...!? use key symbol
45 if (key->sym >= 128) {
46 eDebug("SDL: cannot emulate ASCII");
49 eDebug("SDL: emulate ASCII");
52 if (km == eRCInput::kmAscii) {
53 // skip ESC c or ESC '[' c
60 if (code == SDLK_ESCAPE)
63 if ((code < SDLK_SPACE) ||
64 (code == 0x7e) || // really?
65 (code == SDLK_DELETE))
68 flags |= eRCKey::flagAscii;
71 eDebug("SDL code=%d flags=%d", code, flags);
72 input->keyPressed(eRCKey(this, code, flags));
75 const char *eSDLInputDevice::getDescription() const
80 int eSDLInputDevice::translateKey(SDLKey key)
82 #define P(a) case SDLK_##a: return KEY_##a
83 #define P2(a,b) case SDLK_##a: return KEY_##b
102 P2(QUOTE,APOSTROPHE);
138 P2(LEFTBRACKET,LEFTBRACE);
140 P2(RIGHTBRACKET,RIGHTBRACE);
282 P2(KP_DIVIDE,KPSLASH);
283 P2(KP_MULTIPLY,KPASTERISK);
284 P2(KP_MINUS,KPMINUS);
286 P2(KP_ENTER,KPENTER);
287 P2(KP_EQUALS,KPEQUAL);
314 P2(SCROLLOCK,SCROLLLOCK);
315 P2(RSHIFT,RIGHTSHIFT);
316 P2(LSHIFT,LEFTSHIFT);
338 eDebug("unhandled SDL keycode: %d", key);
350 eSDLInputDriver *eSDLInputDriver::instance;
352 eSDLInputDriver::eSDLInputDriver() : eRCDriver(eRCInput::getInstance())
354 ASSERT(instance == 0);
358 eSDLInputDriver::~eSDLInputDriver()
363 void eSDLInputDriver::keyPressed(const SDL_KeyboardEvent *key)
365 eDebug("km=%d enabled=%d locked=%d",
366 input->getKeyboardMode(), enabled, input->islocked());
368 if (!enabled || input->islocked())
371 std::list<eRCDevice*>::iterator i(listeners.begin());
372 while (i != listeners.end()) {
373 (*i)->handleCode((long)key);
381 eSDLInputDriver driver;
382 eSDLInputDevice device;
385 eRCSDLInit(): driver(), device(&driver)
390 eAutoInitP0<eRCSDLInit> init_rcSDL(eAutoInitNumbers::rc+1, "SDL RC Driver");