int GewiEngine::EventFilter(SDL_Event *event) { static char noChar = '\0'; GewiEngine *gewi = GewiEngine::GetInstance(); char ch; //called inside ZEngine::CheckEvents switch(event->type) { case SDL_MOUSEBUTTONDOWN: if(event->button.button == SDL_BUTTON_LEFT) gewi->SendMessage(event,GE_LDOWN,event->button.x,event->button.y,noChar); if(event->button.button == SDL_BUTTON_RIGHT) gewi->SendMessage(event,GE_RDOWN,event->button.x,event->button.y,noChar); break; case SDL_MOUSEBUTTONUP: if(event->button.button == SDL_BUTTON_LEFT) gewi->SendMessage(event,GE_LUP,event->button.x,event->button.y,noChar); if(event->button.button == SDL_BUTTON_RIGHT) gewi->SendMessage(event,GE_RUP,event->button.x,event->button.y,noChar); break; case SDL_KEYDOWN: ch = TranslateKey(event->key.keysym); gewi->SendMessage(event,GE_KDOWN,0,0,ch); break; case SDL_KEYUP: ch = TranslateKey(event->key.keysym); gewi->SendMessage(event,GE_KUP,0,0,ch); break; default: break; } return 1; //pass the event on, allowing ZEngine to do what it needs }
void ProcessKey(SDL_Event& e) { switch(e.type) { case SDL_KEYDOWN: { dword flags = KF_DOWN|OpJoyKeyFlags(); if(l_shift) flags |= KF_SHIFT; if(r_shift) flags |= KF_ALT; byte key = TranslateKey(e.key.keysym.sym, flags); Handler()->OnKey(key, flags); } break; case SDL_KEYUP: { dword flags = 0; if(l_shift) flags |= KF_SHIFT; if(r_shift) flags |= KF_ALT; byte key = TranslateKey(e.key.keysym.sym, flags); Handler()->OnKey(key, OpJoyKeyFlags()); } break; default: break; } }
void SDLRunner::ProcessEvent(SDL_Event &event, client::Client *client) { switch (event.type) { case SDL_QUIT: client->Closing(); //running = false; break; case SDL_MOUSEBUTTONDOWN: client->KeyEvent(TranslateButton(event.button.button), true); break; case SDL_MOUSEBUTTONUP: client->KeyEvent(TranslateButton(event.button.button), false); break; case SDL_MOUSEMOTION: if( mActive ) { client->MouseEvent(event.motion.xrel, event.motion.yrel); } break; case SDL_KEYDOWN: if(event.key.keysym.unicode){ int uni = event.key.keysym.unicode; if(uni > 0 && uni < 128 && uni != 8 && // no backspace uni != 13 && uni != 10 && uni != 127){ // no enter std::string s; s += (char)uni; client->CharEvent(s); } } client->KeyEvent(TranslateKey(event.key.keysym), true); break; case SDL_KEYUP: client->KeyEvent(TranslateKey(event.key.keysym), false); break; case SDL_ACTIVEEVENT: if( event.active.state & (SDL_APPACTIVE|SDL_APPINPUTFOCUS) ) { //any of the 2 is good if(event.active.gain){ SDL_ShowCursor(0); SDL_WM_GrabInput( SDL_GRAB_ON ); mActive = true; }else{ SDL_WM_GrabInput( SDL_GRAB_OFF ); mActive = false; SDL_ShowCursor(1); } } break; default: break; } }
// ~IInputEventListener virtual bool OnInputEvent( const SInputEvent &event ) { if (true == m_bActive) { #if defined(ORBIS) // FIXME: Using PS3 inputs for ORBIS int nThisKey = event.keyId; int nKey = -1; int nInput = GetPortInt(&m_actInfo, EIP_Key); int tableSize = sizeof(PS3KeyTable)/sizeof(PS3KeyTable[0]); if ( nInput>=0 && nInput<tableSize ) nKey = PS3KeyTable[nInput]; #else // Translate key, check value const int nThisKey = TranslateKey(event.keyId); const int nKey = GetPortInt(&m_actInfo, EIP_Key); #endif if (nKey == nThisKey) { // Return based on state if (eIS_Pressed == event.state) ActivateOutput(&m_actInfo, EOP_Pressed, true); else if (eIS_Released == event.state) ActivateOutput(&m_actInfo, EOP_Released, true); } } // Let other listeners handle it return false; }
// Translates a key and sends it void SendKey(TKeyCode aCode, TUint aModifiers) { char buf[16]; // Reset scrollback seen_key_event = 1; // Interrupt paste term_nopaste(); // Try to translate as a control character int xbytes = TranslateKey(aCode, aModifiers, buf); assert(xbytes < 16); if ( xbytes > 0 ) { // Send control key codes as is ldisc_send(buf, xbytes, 1); } else if ( xbytes == -1 ) { // Not translated, probably a normal letter if ( aCode < ENonCharacterKeyBase ) { wchar_t wc = (wchar_t) aCode; luni_send(&wc, 1, 1); } } }
static void handle_keyboard(const int numevents, DIDEVICEOBJECTDATA *keybuf) { int i; SDL_keysym keysym; for ( i=0; i<numevents; ++i ) { if ( keybuf[i].dwData & 0x80 ) { posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(keybuf[i].dwOfs, &keysym, 1)); } else { posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(keybuf[i].dwOfs, &keysym, 0)); } } }
static void keyboard_update(void) { static SDL_keysym keysym; static XKEYBOARD_STROKE keystroke; if( 0 > XInputGetKeystroke(&keystroke) ) return; if (keystroke.ucKeyCode == 0) return; if ( keystroke.ucFlags & XKEYBOARD_KEYUP ) { SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(keystroke,&keysym, 1)); } else { SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(keystroke,&keysym, 0)); } }
void AtariGemdos_PumpEvents(_THIS) { int i; SDL_keysym keysym; /* Update pressed keys */ SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS); while (Cconis()!=DEV_BUSY) { unsigned long key_pressed; unsigned char scancode, asciicode; key_pressed=Cnecin(); asciicode = key_pressed; scancode = key_pressed >> 16; gemdos_currentkeyboard[scancode]=0xFF; gemdos_currentascii[scancode]=asciicode; } /* Read special keys */ UpdateSpecialKeys(Kbshift(-1)); /* Now generate events */ for (i=0; i<ATARIBIOS_MAXKEYS; i++) { /* Key pressed ? */ if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i]) SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_TRUE)); /* Key unpressed ? */ if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i]) SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_FALSE)); } if (use_dev_mouse) { SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE); } else { SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE); } /* Will be previous table */ SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS); }
void keydown( int key ) { agk::KeyDown( TranslateKey(key) ); int ch = AsciiKey(key); if ( ch != 0 ) { agk::CharDown( ch ); } }
void I_HandleKeyboardEvent(SDL_Event *sdlevent) { // XXX: passing pointers to event for access after this function // has terminated is undefined behaviour event_t event; switch (sdlevent->type) { case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = TranslateKey(&sdlevent->key.keysym); event.data2 = GetLocalizedKey(&sdlevent->key.keysym); event.data3 = GetTypedChar(&sdlevent->key.keysym); if (event.data1 != 0) { D_PostEvent(&event); } break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = TranslateKey(&sdlevent->key.keysym); // data2/data3 are initialized to zero for ev_keyup. // For ev_keydown it's the shifted Unicode character // that was typed, but if something wants to detect // key releases it should do so based on data1 // (key ID), not the printable char. event.data2 = 0; event.data3 = 0; if (event.data1 != 0) { D_PostEvent(&event); } break; default: break; } }
virtual void OnKeyup(wxKeyEvent& event) { int key = event.GetKeyCode(); // printf("ku:%c\n", key); dword flags = 0; if(event.AltDown()) flags |= KF_ALT; if(event.ShiftDown()) flags |= KF_SHIFT; TranslateKey(key, flags); Handler()->OnKey(key, OpJoyKeyFlags()); }
/* * TextInputKey: User pressed a key on text input box. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool TextInputKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ char string[MAXSAY + 1]; int action; BOOL bValid; void *action_data; if (key == VK_RETURN && !held_down) { UserDidSomething(); ComboBox_GetText(hwndInput, string, MAXSAY + 1); if (string[0] == 0) return True; SetFocus(hMain); bValid = ParseGotText(string); // Add it to the history. if (*string && bValid) { BOOL bAdd = TRUE; int iCount; char achHead[MAXSAY+1]; iCount = ComboBox_GetCount(hwndInput); if (iCount > 0) { ComboBox_GetLBText(hwndInput, 0, achHead); if (0 == strcmp(achHead, string)) bAdd = FALSE; } if (bAdd) { ComboBox_InsertString(hwndInput, 0, string); if (iCount > EDITBOX_HISTORY) ComboBox_DeleteString(hwndInput, iCount); } } return True; } // Check for special keys action = TranslateKey(key, textin_key_table, &action_data); if (action == A_NOACTION) return False; PerformAction(action, action_data); return True; }
void SDL_ANDROID_processAndroidTrackballDampening() { SDL_keysym keysym; if( !TrackballDampening ) return; if( SDL_GetTicks() - lastTrackballAction > TrackballDampening ) { if( upPressed ) SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_UP ,&keysym) ); if( downPressed ) SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_DOWN ,&keysym) ); if( leftPressed ) SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_LEFT ,&keysym) ); if( rightPressed ) SDL_SendKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_RIGHT ,&keysym) ); upPressed = 0; downPressed = 0; leftPressed = 0; rightPressed = 0; } }
bool Video::SDLSystem::Update(Video::Event *E) { SDL_Event SE; if (SDL_PollEvent(&SE)) { switch (SE.type) { case SDL_KEYDOWN: E->Key.Type = EVT_KEYDOWN; E->Key.Key = TranslateKey(SE.key.keysym.sym); return true; case SDL_KEYUP: E->Key.Type = EVT_KEYUP; E->Key.Key = TranslateKey(SE.key.keysym.sym); return true; case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: E->Mouse.Type = EVT_MOUSE; E->Mouse.Buttons = SDL_GetMouseState(&E->Mouse.XOffset,&E->Mouse.YOffset); E->Mouse.XOffset -= Width / 2; E->Mouse.YOffset -= Height / 2; E->Mouse.XOffset *= 4; E->Mouse.YOffset *= -4; SDL_WarpMouse(Width / 2,Height / 2); return true; case SDL_QUIT: E->Type = EVT_QUIT; return true; default: return Update(E); } } else { return false; } }
//============================================================================= // eControl::keyReleaseEvent //----------------------------------------------------------------------------- void eControl::keyReleaseEvent(QKeyEvent* event) { if(event->isAutoRepeat()) { event->ignore(); return; } int key = 0; dword flags = 0; EventKeyFlags(event, &key, &flags); TranslateKey(key, flags); Handler()->OnKey(key, OpJoyKeyFlags()); key > 0 ? event->accept() : event->ignore(); }
virtual void OnKeydown(wxKeyEvent& event) { int key = event.GetKeyCode(); if(HasCapture() && key == WXK_ESCAPE) { KillMouseFocus(); return; } // printf("kd:%c\n", key); dword flags = KF_DOWN|OpJoyKeyFlags(); if(event.AltDown()) flags |= KF_ALT; if(event.ShiftDown()) flags |= KF_SHIFT; TranslateKey(key, flags); Handler()->OnKey(key, flags); }
JNIEXPORT jboolean JNICALL JAVA_EXPORT_NAME(SDLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action, jint unicode ) { if( isTrackballUsed ) if( processAndroidTrackball(key, action) ) return; SDL_keysym keysym; SDL_keysym *ks = TranslateKey(key, &keysym); ks->unicode = unicode; if (ks->sym == KEYCODE_UNKNOWN) { return 0; } else { SDL_SendKeyboardKey( action ? SDL_PRESSED : SDL_RELEASED, ks); return 1; } }
JNIEXPORT jint JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action ) { if( !SDL_CurrentVideoSurface ) return 1; SDL_scancode sdlKey = TranslateKey(key); if( sdlKey == SDLK_NO_REMAP || sdlKey == SDLK_UNKNOWN ) return 0; if( sdlKey == SDLK_LCLICK ) { SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT ); } else if( sdlKey == SDLK_RCLICK ) { SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT ); } else { SDL_ANDROID_MainThreadPushKeyboardKey( action ? SDL_PRESSED : SDL_RELEASED, sdlKey ); } return 1; }
// Get the localized version of the key press. This takes into account the // keyboard layout, but does not apply any changes due to modifiers, (eg. // shift-, alt-, etc.) static int GetLocalizedKey(SDL_Keysym *sym) { // When using Vanilla mapping, we just base everything off the scancode // and always pretend the user is using a US layout keyboard. if (vanilla_keyboard_mapping) { return TranslateKey(sym); } else { int result = sym->sym; if (result < 0 || result >= 128) { result = 0; } return result; } }
static int GetTypedChar(SDL_Event *event) { int key; // If Vanilla keyboard mapping enabled, the keyboard // scan code is used to give the character typed. // This does not change depending on keyboard layout. // If you have a German keyboard, pressing 'z' will // give 'y', for example. It is desirable to be able // to fix this so that people with non-standard // keyboard mappings can type properly. If vanilla // mode is disabled, use the properly translated // version. if (vanilla_keyboard_mapping) { key = TranslateKey(&event->key.keysym); // Is shift held down? If so, perform a translation. if (shiftdown > 0) { if (key >= 0 && key < arrlen(shiftxform)) { key = shiftxform[key]; } else { key = 0; } } return key; } else { // Unicode value, from key layout. return tolower(event->key.keysym.unicode); } }
KeyEvent::KeyEvent(const MSG& msg) { int res; BYTE keys[256]; wchar_t buffer[256]; event=msg; if (msg.message==WM_KEYDOWN || msg.message==WM_SYSKEYDOWN) { type=down; } else { type=up; } /* ignore */ GetKeyboardState(keys); res=::ToUnicode(msg.wParam,(msg.lParam/65536) % 2048,keys,buffer,sizeof(buffer)/sizeof(wchar_t),0); if (res>0) { text=std::wstring(buffer,res); } else { text=L""; } qualifier=EvaluateKeyQualifier(keys); key=TranslateKey(msg.wParam,qualifier); if (text.empty() && (qualifier & (qualifierControlLeft|qualifierControlRight))) { if (msg.wParam>=65 && msg.wParam<=90) { if (qualifier & (qualifierShiftLeft|qualifierShiftRight)) { text.assign(1,(wchar_t)msg.wParam); } else { text.assign(1,(wchar_t)msg.wParam+L'a'-L'A'); } } else if (msg.wParam!=VK_CONTROL) { text.assign(1,(wchar_t)msg.wParam); } } }
void CRBXInput::ReadKeys( KEYS& _key, bool& _keypressed ) { static KEYS lastkey = NOKEY; neutrino_msg_t msg; neutrino_msg_data_t data; ReadFromLircd( _key ); if( NOKEY != _key ) { _keypressed = true; lastkey = _key; } else { if( NOKEY != lastkey ) { _key = lastkey; _keypressed = false; } lastkey = NOKEY; } rcinput.getMsg_ms(&msg, &data, 100 ); if( msg != CRCInput::RC_nokey && msg != CRCInput::RC_timeout ) { std::cout << "got something from rcinput!" << std::endl; _key = TranslateKey( (int)msg ); _keypressed = !data; } }
/* * StatInputKey: User pressed a key on stat group button or list box. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool StatInputKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ int action; void *action_data; UserDidSomething(); /* See if stat button handles this key */ action = TranslateKey(key, stats_key_table, &action_data); if (action == A_NOACTION) return False; switch(action) { case A_TABFWD: TextInputSetFocus(True); break; case A_TABBACK: SetFocus(cinfo->hMain); // ajw //InventorySetFocus(False); break; case A_NEXT: StatsMoveButtonFocus(hwnd, True); break; case A_PREV: StatsMoveButtonFocus(hwnd, False); break; default: if (!held_down) PerformAction(action, action_data); break; } return True; }
// Go check a Flash event queue for events SDL should be aware of! void FLASH_PumpEvents(_THIS) { if (!FLASH_EMPTY_PARAMS) FLASH_EMPTY_PARAMS = AS3_Array(""); // Event Vars AS3_Val mouseEvent, mouseEvents, mousePosition, keyboardEvent, keyboardEvents; int buttonState, rawKeyboardEvent, scanCode, keyState; SDL_keysym keysym; mousePosition = AS3_CallS( "pumpMousePosition", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); mouseEvents = AS3_CallS( "pumpMouseEvents", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); keyboardEvents = AS3_CallS( "pumpKeyEvents", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); // Mouse Position if (mousePosition) { AS3_ObjectValue( mousePosition, "x:IntType, y:IntType", &FLASH_mouseX, &FLASH_mouseY ); SDL_PrivateMouseMotion( 0, 0, FLASH_mouseX, FLASH_mouseY ); } // Mouse Click Events while( AS3_IntValue(AS3_GetS(mouseEvents, "size")) > 0 ) { mouseEvent = AS3_CallS( "dequeue", mouseEvents, FLASH_EMPTY_PARAMS ); buttonState = AS3_IntValue( mouseEvent )? SDL_PRESSED: SDL_RELEASED; SDL_PrivateMouseButton(buttonState, SDL_BUTTON_LEFT, FLASH_mouseX, FLASH_mouseY); } // Keyboard Events while( AS3_IntValue(AS3_GetS(keyboardEvents, "size")) > 0 ) { keyboardEvent = AS3_CallS( "dequeue", keyboardEvents, FLASH_EMPTY_PARAMS ); rawKeyboardEvent = AS3_IntValue( keyboardEvent ); scanCode = rawKeyboardEvent & 0xFF; // Packed event format: 9th bit for press/release, lower 8 bits for scan code keyState = rawKeyboardEvent >> 8; SDL_PrivateKeyboard(keyState, TranslateKey(scanCode, &keysym)); } }
/* * InventoryKey: User pressed a key on the inventory list. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool InventoryKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { ID id; Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ int action, params; InvItem *item; void *action_data; Bool inform; UserDidSomething(); /* See if inventory handles this key specially */ action = TranslateKey(key, inventory_key_table, &action_data); if (action == A_NOACTION) return False; // Skip held-down keys, except for moving cursor around if (held_down && !IsCursorAction(action)) return True; item = InventoryGetCurrentItem(); if (item == NULL) id = INVALID_ID; else id = item->obj->id; // See if we should inform modules about event inform = True; switch (action) { case A_TABFWD: case A_TABBACK: case A_TOGGLEUSE: case A_USE: case A_UNUSE: case A_DROP: case A_APPLY: case A_LOOKINVENTORY: case A_SELECT: action_data = (void *) id; break; default: inform = False; // Modules will be informed in PerformAction call below } // See if a module wants to handle this action if (inform) if (ModuleEvent(EVENT_USERACTION, action, action_data) == False) return True; if (IsCursorAction(action)) { InventoryCursorMove(action); return True; } switch (action) { case A_TABFWD: TextInputSetFocus(True); // ajw //StatsSetFocus(True); break; case A_TABBACK: SetFocus(cinfo->hMain); break; case A_TOGGLEUSE: if (id != INVALID_ID) { if (item->obj->flags & OF_APPLYABLE) StartApply(id); else ToggleUse(id); } break; case A_USE: if (id != INVALID_ID) RequestUse(id); break; case A_UNUSE: if (id != INVALID_ID) RequestUnuse(id); break; case A_DROP: if (id != INVALID_ID) InventoryDropCurrentItem(NULL); break; case A_APPLY: if (id != INVALID_ID) StartApply(id); break; case A_LOOKINVENTORY: if (id == INVALID_ID) break; params = DESC_DROP; if (item->is_using) params |= DESC_UNUSE; else if (item->obj->flags & OF_APPLYABLE) params |= DESC_APPLY; else params |= DESC_USE; SetDescParams(cinfo->hMain, params); RequestLook(id); break; case A_SELECT: if (id != INVALID_ID) SelectedObject(id); break; default: PerformAction(action, action_data); break; } return True; }
/* * Translates key and button events. */ bool CLinuxInputDevice::KeyEvent(const struct input_event& levt, XBMC_Event& devt) { int code = levt.code; /* map touchscreen and smartpad events to button mouse */ if (code == BTN_TOUCH || code == BTN_TOOL_FINGER) code = BTN_MOUSE; if ((code >= BTN_MOUSE && code < BTN_JOYSTICK) || code == BTN_TOUCH) { /* ignore repeat events for buttons */ if (levt.value == 2) return false; devt.type = levt.value ? XBMC_MOUSEBUTTONDOWN : XBMC_MOUSEBUTTONUP; devt.button.state = levt.value ? XBMC_PRESSED : XBMC_RELEASED; devt.button.type = devt.type; devt.button.x = m_mouseX; devt.button.y = m_mouseY; switch (levt.code) { case BTN_RIGHT: devt.button.button = XBMC_BUTTON_RIGHT; break; case BTN_LEFT: devt.button.button = XBMC_BUTTON_LEFT; break; case BTN_MIDDLE: devt.button.button = XBMC_BUTTON_RIGHT; break; case BTN_FORWARD: devt.button.button = XBMC_BUTTON_WHEELDOWN; break; case BTN_BACK: devt.button.button = XBMC_BUTTON_WHEELUP; break; case BTN_TOUCH: devt.button.button = XBMC_BUTTON_LEFT; break; case BTN_TOOL_DOUBLETAP: devt.button.button = XBMC_BUTTON_RIGHT; break; default: CLog::Log(LOGWARNING, "CLinuxInputDevice::KeyEvent: Unknown mouse button code: %d\n", levt.code); return false; } } else { XBMCKey key = TranslateKey(code); if (key == XBMCK_UNKNOWN) { CLog::Log(LOGDEBUG, "CLinuxInputDevice::KeyEvent: TranslateKey returned XBMCK_UNKNOWN from code(%d)", code); return false; } devt.type = levt.value ? XBMC_KEYDOWN : XBMC_KEYUP; devt.key.type = devt.type; // warning, key.keysym.scancode is unsigned char so 0 - 255 only devt.key.keysym.scancode = code; devt.key.keysym.sym = key; devt.key.keysym.mod = UpdateModifiers(devt); devt.key.keysym.unicode = 0; KeymapEntry entry; entry.code = code; if (GetKeymapEntry(entry)) { int keyMapValue; if (devt.key.keysym.mod & (XBMCKMOD_SHIFT | XBMCKMOD_CAPS)) keyMapValue = entry.shift; else if (devt.key.keysym.mod & XBMCKMOD_ALT) keyMapValue = entry.alt; else if (devt.key.keysym.mod & XBMCKMOD_META) keyMapValue = entry.altShift; else keyMapValue = entry.base; if (keyMapValue != XBMCK_UNKNOWN) { devt.key.keysym.sym = (XBMCKey) keyMapValue; if (keyMapValue > 0 && keyMapValue < 127) { devt.key.keysym.unicode = devt.key.keysym.sym; } } } } return true; }
LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { extern int posted; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { SDL_keysym keysym; #ifdef SDL_VIDEO_DRIVER_GAPI if(this->hidden->gapiInfo) { if (wParam == 0x84 || wParam == 0x5B) return 0; wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform); } #endif if ( lParam&REPEATED_KEYMASK ) { return(0); } switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } #ifdef NO_GETKEYBOARDSTATE if ( SDL_TranslateUNICODE ) { MSG m; m.hwnd = hwnd; m.message = msg; m.wParam = wParam; m.lParam = lParam; m.time = 0; if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { GetMessage(&m, hwnd, 0, WM_USER); wParam = m.wParam; } } #endif posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { SDL_keysym keysym; #ifdef SDL_VIDEO_DRIVER_GAPI if(this->hidden->gapiInfo) { if (wParam == 0x84 || wParam == 0x5B) return 0; wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform); } #endif switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(wParam,HIWORD(lParam),&keysym,0)); } return(0); #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { const DWORD val = (DWORD) (wParam & 0xFFF0); if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) { if (this->hidden->dibInfo && !allow_screensaver) { return(0); } } } #endif default: { if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.hwnd = hwnd; wmmsg.msg = msg; wmmsg.wParam = wParam; wmmsg.lParam = lParam; posted = SDL_PrivateSysWMEvent(&wmmsg); } else if (userWindowProc) { return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); } } break; } return(DefWindowProc(hwnd, msg, wParam, lParam)); }
LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { XBMC_Event newEvent; ZeroMemory(&newEvent, sizeof(newEvent)); static HDEVNOTIFY hDeviceNotify; if (uMsg == WM_CREATE) { SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG)(((LPCREATESTRUCT)lParam)->lpCreateParams)); DIB_InitOSKeymap(); g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay")); shcne.pidl = NULL; shcne.fRecursive = TRUE; long fEvents = SHCNE_DRIVEADD | SHCNE_DRIVEREMOVED | SHCNE_MEDIAREMOVED | SHCNE_MEDIAINSERTED; SHChangeNotifyRegister(hWnd, SHCNRF_ShellLevel | SHCNRF_NewDelivery, fEvents, WM_MEDIA_CHANGE, 1, &shcne); RegisterDeviceInterfaceToHwnd(USB_HID_GUID, hWnd, &hDeviceNotify); return 0; } m_pEventFunc = (PHANDLE_EVENT_FUNC)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!m_pEventFunc) return DefWindowProc(hWnd, uMsg, wParam, lParam); if(g_uQueryCancelAutoPlay != 0 && uMsg == g_uQueryCancelAutoPlay) return S_FALSE; switch (uMsg) { case WM_CLOSE: case WM_QUIT: case WM_DESTROY: newEvent.type = XBMC_QUIT; m_pEventFunc(newEvent); break; case WM_SHOWWINDOW: { bool active = g_application.m_AppActive; g_application.m_AppActive = wParam != 0; if (g_application.m_AppActive != active) g_Windowing.NotifyAppActiveChange(g_application.m_AppActive); CLog::Log(LOGDEBUG, __FUNCTION__"Window is %s", g_application.m_AppActive ? "shown" : "hidden"); } break; case WM_ACTIVATE: { bool active = g_application.m_AppActive; if (HIWORD(wParam)) { g_application.m_AppActive = false; } else { WINDOWPLACEMENT lpwndpl; lpwndpl.length = sizeof(lpwndpl); if (LOWORD(wParam) != WA_INACTIVE) { if (GetWindowPlacement(hWnd, &lpwndpl)) g_application.m_AppActive = lpwndpl.showCmd != SW_HIDE; } else { g_application.m_AppActive = g_Windowing.WindowedMode(); } } if (g_application.m_AppActive != active) g_Windowing.NotifyAppActiveChange(g_application.m_AppActive); CLog::Log(LOGDEBUG, __FUNCTION__"Window is %s", g_application.m_AppActive ? "active" : "inactive"); } break; case WM_SETFOCUS: case WM_KILLFOCUS: g_application.m_AppFocused = uMsg == WM_SETFOCUS; g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused); if (uMsg == WM_KILLFOCUS) { CStdString procfile; if (CWIN32Util::GetFocussedProcess(procfile)) CLog::Log(LOGDEBUG, __FUNCTION__": Focus switched to process %s", procfile.c_str()); } break; case WM_SYSKEYDOWN: switch (wParam) { case VK_F4: //alt-f4, default event quit. return(DefWindowProc(hWnd, uMsg, wParam, lParam)); case VK_RETURN: //alt-return if ((lParam & REPEATED_KEYMASK) == 0) g_graphicsContext.ToggleFullScreenRoot(); return 0; } //deliberate fallthrough case WM_KEYDOWN: { switch (wParam) { case VK_CONTROL: if ( lParam & EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ if (GetKeyState(VK_LSHIFT) & 0x8000) wParam = VK_LSHIFT; else if (GetKeyState(VK_RSHIFT) & 0x8000) wParam = VK_RSHIFT; break; case VK_MENU: if ( lParam & EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } XBMC_keysym keysym; TranslateKey(wParam, HIWORD(lParam), &keysym, 1); newEvent.type = XBMC_KEYDOWN; newEvent.key.keysym = keysym; m_pEventFunc(newEvent); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: { uint32_t scanCodeL = MapVirtualKey(VK_LSHIFT, MAPVK_VK_TO_VSC); uint32_t scanCodeR = MapVirtualKey(VK_RSHIFT, MAPVK_VK_TO_VSC); uint32_t keyCode = (uint32_t)((lParam & 0xFF0000) >> 16); if (keyCode == scanCodeL) wParam = VK_LSHIFT; else if (keyCode == scanCodeR) wParam = VK_RSHIFT; } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } XBMC_keysym keysym; TranslateKey(wParam, HIWORD(lParam), &keysym, 1); if (wParam == VK_SNAPSHOT) newEvent.type = XBMC_KEYDOWN; else newEvent.type = XBMC_KEYUP; newEvent.key.keysym = keysym; m_pEventFunc(newEvent); } return(0); case WM_APPCOMMAND: // MULTIMEDIA keys are mapped to APPCOMMANDS { CLog::Log(LOGDEBUG, "WinEventsWin32.cpp: APPCOMMAND %d", GET_APPCOMMAND_LPARAM(lParam)); newEvent.appcommand.type = XBMC_APPCOMMAND; newEvent.appcommand.action = GET_APPCOMMAND_LPARAM(lParam); if (m_pEventFunc(newEvent)) return TRUE; else return DefWindowProc(hWnd, uMsg, wParam, lParam); } case WM_GESTURENOTIFY: { OnGestureNotify(hWnd, lParam); return DefWindowProc(hWnd, WM_GESTURENOTIFY, wParam, lParam); } case WM_GESTURE: { OnGesture(hWnd, lParam); return 0; } case WM_SYSCHAR: if (wParam == VK_RETURN) //stop system beep on alt-return return 0; break; case WM_SETCURSOR: if (HTCLIENT != LOWORD(lParam)) g_Windowing.ShowOSMouse(true); break; case WM_MOUSEMOVE: newEvent.type = XBMC_MOUSEMOTION; newEvent.motion.x = GET_X_LPARAM(lParam); newEvent.motion.y = GET_Y_LPARAM(lParam); newEvent.motion.state = 0; m_pEventFunc(newEvent); return(0); case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: newEvent.type = XBMC_MOUSEBUTTONDOWN; newEvent.button.state = XBMC_PRESSED; newEvent.button.x = GET_X_LPARAM(lParam); newEvent.button.y = GET_Y_LPARAM(lParam); newEvent.button.button = 0; if (uMsg == WM_LBUTTONDOWN) newEvent.button.button = XBMC_BUTTON_LEFT; else if (uMsg == WM_MBUTTONDOWN) newEvent.button.button = XBMC_BUTTON_MIDDLE; else if (uMsg == WM_RBUTTONDOWN) newEvent.button.button = XBMC_BUTTON_RIGHT; m_pEventFunc(newEvent); return(0); case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: newEvent.type = XBMC_MOUSEBUTTONUP; newEvent.button.state = XBMC_RELEASED; newEvent.button.x = GET_X_LPARAM(lParam); newEvent.button.y = GET_Y_LPARAM(lParam); newEvent.button.button = 0; if (uMsg == WM_LBUTTONUP) newEvent.button.button = XBMC_BUTTON_LEFT; else if (uMsg == WM_MBUTTONUP) newEvent.button.button = XBMC_BUTTON_MIDDLE; else if (uMsg == WM_RBUTTONUP) newEvent.button.button = XBMC_BUTTON_RIGHT; m_pEventFunc(newEvent); return(0); case WM_MOUSEWHEEL: { // SDL, which our events system is based off, sends a MOUSEBUTTONDOWN message // followed by a MOUSEBUTTONUP message. As this is a momentary event, we just // react on the MOUSEBUTTONUP message, resetting the state after processing. newEvent.type = XBMC_MOUSEBUTTONDOWN; newEvent.button.state = XBMC_PRESSED; // the coordinates in WM_MOUSEWHEEL are screen, not client coordinates POINT point; point.x = GET_X_LPARAM(lParam); point.y = GET_Y_LPARAM(lParam); WindowFromScreenCoords(hWnd, &point); newEvent.button.x = (uint16_t)point.x; newEvent.button.y = (uint16_t)point.y; newEvent.button.button = GET_Y_LPARAM(wParam) > 0 ? XBMC_BUTTON_WHEELUP : XBMC_BUTTON_WHEELDOWN; m_pEventFunc(newEvent); newEvent.type = XBMC_MOUSEBUTTONUP; newEvent.button.state = XBMC_RELEASED; m_pEventFunc(newEvent); } return(0); case WM_SIZE: newEvent.type = XBMC_VIDEORESIZE; newEvent.resize.type = XBMC_VIDEORESIZE; newEvent.resize.w = GET_X_LPARAM(lParam); newEvent.resize.h = GET_Y_LPARAM(lParam); if (newEvent.resize.w * newEvent.resize.h) m_pEventFunc(newEvent); return(0); case WM_MEDIA_CHANGE: { // There may be multiple notifications for one event // There are also a few events we're not interested in, but they cause no harm // For example SD card reader insertion/removal long lEvent; PIDLIST_ABSOLUTE *ppidl; HANDLE hLock = SHChangeNotification_Lock((HANDLE)wParam, (DWORD)lParam, &ppidl, &lEvent); if (hLock) { char drivePath[MAX_PATH+1]; if (!SHGetPathFromIDList(ppidl[0], drivePath)) break; switch(lEvent) { case SHCNE_DRIVEADD: case SHCNE_MEDIAINSERTED: CLog::Log(LOGDEBUG, __FUNCTION__": Drive %s Media has arrived.", drivePath); if (GetDriveType(drivePath) == DRIVE_CDROM) g_application.getApplicationMessenger().OpticalMount(drivePath, true); else CWin32StorageProvider::SetEvent(); break; case SHCNE_DRIVEREMOVED: case SHCNE_MEDIAREMOVED: CLog::Log(LOGDEBUG, __FUNCTION__": Drive %s Media was removed.", drivePath); if (GetDriveType(drivePath) == DRIVE_CDROM) g_application.getApplicationMessenger().OpticalUnMount(drivePath); else CWin32StorageProvider::SetEvent(); break; } SHChangeNotification_Unlock(hLock); } break; } case WM_POWERBROADCAST: if (wParam==PBT_APMSUSPEND) { CLog::Log(LOGDEBUG,"WM_POWERBROADCAST: PBT_APMSUSPEND event was sent"); CWin32PowerSyscall::SetOnSuspend(); } else if(wParam==PBT_APMRESUMEAUTOMATIC) { CLog::Log(LOGDEBUG,"WM_POWERBROADCAST: PBT_APMRESUMEAUTOMATIC event was sent"); CWin32PowerSyscall::SetOnResume(); } break; case WM_DEVICECHANGE: { PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam; CStdString dbcc_name(b->dbcc_name); dbcc_name = CKeymapLoader::ParseWin32HIDName(b->dbcc_name); switch (wParam) { case DBT_DEVICEARRIVAL: CKeymapLoader().DeviceAdded(dbcc_name); break; case DBT_DEVICEREMOVECOMPLETE: CKeymapLoader().DeviceRemoved(dbcc_name); break; case DBT_DEVNODES_CHANGED: //CLog::Log(LOGDEBUG, "HID Device Changed"); //We generally don't care about Change notifications, only need to know if a device is removed or added to rescan the device list break; } break; } case WM_PAINT: //some other app has painted over our window, mark everything as dirty g_windowManager.MarkDirty(); break; } return(DefWindowProc(hWnd, uMsg, wParam, lParam)); }
/* The main Win32 event handler */ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { extern int posted; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { SDL_keysym keysym; #ifdef _WIN32_WCE // Drop GAPI artefacts if (wParam == 0x84 || wParam == 0x5B) return 0; // Rotate key if necessary if (this->hidden->orientation != SDL_ORIENTATION_UP) wParam = rotateKey(wParam, this->hidden->orientation); #endif /* Ignore repeated keys */ if ( lParam&REPEATED_KEYMASK ) { return(0); } switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } #ifdef NO_GETKEYBOARDSTATE /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ if ( SDL_TranslateUNICODE ) { MSG m; m.hwnd = hwnd; m.message = msg; m.wParam = wParam; m.lParam = lParam; m.time = 0; if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { GetMessage(&m, hwnd, 0, WM_USER); wParam = m.wParam; } } #endif /* NO_GETKEYBOARDSTATE */ posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { SDL_keysym keysym; #ifdef _WIN32_WCE // Drop GAPI artifacts if (wParam == 0x84 || wParam == 0x5B) return 0; // Rotate key if necessary if (this->hidden->orientation != SDL_ORIENTATION_UP) wParam = rotateKey(wParam, this->hidden->orientation); #endif switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } /* Windows only reports keyup for print screen */ if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(wParam,HIWORD(lParam),&keysym,0)); } return(0); #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { if ((wParam&0xFFF0)==SC_SCREENSAVE || (wParam&0xFFF0)==SC_MONITORPOWER) return(0); } /* Fall through to default processing */ #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ default: { /* Only post the event if we're watching for it */ if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.hwnd = hwnd; wmmsg.msg = msg; wmmsg.wParam = wParam; wmmsg.lParam = lParam; posted = SDL_PrivateSysWMEvent(&wmmsg); /* DJM: If the user isn't watching for private messages in her SDL event loop, then pass it along to any win32 specific window proc. */ } else if (userWindowProc) { return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); } } break; } return(DefWindowProc(hwnd, msg, wParam, lParam)); }
void CRBXInput::ReadFromLircd( KEYS& _key ) { if( -1 == lircd ) return; // std::cout << "read from LIRCD :" << std::endl; fd_set read_sock; struct timeval tv; int rc = 0; _key = NOKEY; // std::cout << "read data from lircd" << std::endl; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO( &read_sock ); FD_SET( lircd, &read_sock ); rc = select( lircd + 1, &read_sock, NULL, NULL, &tv ); if( 0 == rc ) { // std::cout << "read from LIRCD 2:" << std::endl; return; // nothing to read from lircd } // std::cout << "read from LIRCD 0:" << std::endl; if( -1 == rc ) { //something wrong, don't read from lircd anymore // std::cout << "read from LIRCD 1:" << std::endl; close( lircd ); lircd = -1; return; } std::string instring; char buffer[128]; // std::cout << "read data from socket" << std::endl; while( 0 < ( rc = recv( lircd, buffer, 128, 0 ) ) ) { int i; for( i = 0; i < rc; i++ ) { instring += buffer[i]; } if( rc < 128 ) break; } if( 0 == rc ) { //lircd closed connection or some problems, don't read any more from lircd close( lircd ); lircd = -1; return; } else if( rc < 0 && errno != EAGAIN ) { std::cout << "Error on lircd socket while reading" << std::endl; close( lircd ); lircd = -1; return; } if( 0 == instring.size() ) return; std::cout << "Data read from lircd:" << std::endl << instring << std::endl; // Parse strings std::string::size_type start = 0; std::string::size_type end = 0; while( end < instring.size() ) { for( int part = 0; part < 4; part++ ) { std::string sub; std::string delim = (part == 3)?"\n":" "; end = instring.find( delim, start ); sub = instring.substr( start, end - start ); // std::cout << "part: " << part << std::endl; switch( part ) { case 0: /* internal code */ case 1: /* repeat count */ case 3: /* rc name */ break; case 2: /* button name */ _key = TranslateKey( sub ); // std::cout << sub << " translated = " << this->key << std::endl; break; } start = ++end; } } }