GLvoid keyboardCallback(unsigned char key, int x, int y, jboolean up) { if (key == 127) { pressKey("DELETE", up); } else if (key == 27) { pressKey("BACK", up); } else if (key >= 32) { char keyString[] = { (char) key, 0 }; pressKey(keyString, up); } }
TEST_F( Ginga, descriptor_moveLeft_moveRight_moveUp_moveDown1 ) { ASSERT_TRUE( play("descriptor/moveLeft_moveRight_moveUp_moveDown/moveLeft_moveRight_moveUp_moveDown.ncl") ); ASSERT_TRUE( compareTo("blue360x288_red360x288_green360x288_yellow360x288_blueSelected") ); ASSERT_TRUE( pressKey( ::util::key::cursor_down )); ASSERT_TRUE( compareTo("blue360x288_red360x288_green360x288_yellow360x288_redSelected") ); ASSERT_TRUE( pressKey( ::util::key::cursor_right )); ASSERT_TRUE( compareTo("blue360x288_red360x288_green360x288_yellow360x288_yellowSelected") ); ASSERT_TRUE( pressKey( ::util::key::cursor_up )); ASSERT_TRUE( compareTo("blue360x288_red360x288_green360x288_yellow360x288_greenSelected") ); ASSERT_TRUE( pressKey( ::util::key::cursor_left )); ASSERT_TRUE( compareTo("blue360x288_red360x288_green360x288_yellow360x288_blueSelected") ); }
int main() { usbBegin(); PORTB |= _BV(PB0); // Pullup on button while(1) { usbPoll(); if(!(PINB & _BV(PB0))) { // button pressed pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_A); // press pressKey(0, 0); // release } } return 0; }
TEST_F( Ginga, media_dinamic_width2 ) { ASSERT_TRUE( play("media/width/dinamic_width2.ncl") ); ASSERT_TRUE( compareTo("blue720x576") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("blue360x576_black360x576") ); }
// addChar //-------------------------------------------------------------------------- void cInputField::addChar(int newChar) { pressKey(newChar); // Check if the character should be excluded. if (strchr(excludedCharacters, newChar) == 0) { // Add the character. if(insertMode) { // ins, move stuff forward if((cursorPos+1)<maxCharCount) { memmove(destString+cursorPos+1,destString+cursorPos, maxCharCount-(cursorPos+1)); } } int replacedChar=destString[cursorPos]; destString[cursorPos] = newChar; if (cursorPos <= maxCharCount) { if(replacedChar=='\0') destString[cursorPos+1] = '\0'; } else { destString[maxCharCount] = '\0'; } assert(cursorPos < maxCharCount); if (cursorPos < maxCharCount - 1) { cursorPos++; } } if(textaction != 0) textaction(this); } // addChar
void SceneGame::update() { unsigned int i; // if keyboard is up, check for key press if(keyboardUp) { // update the keyboard state s3eKeyboardUpdate(); // see if a key is pressed for(i=0; i<26; i++) { if(s3eKeyboardGetState(s3eKeys[i]) != 0) { pressKey(i); playInputSound(); } } } // check for back button pressed if(s3eKeyboardGetState(s3eKeyAbsBSK) != 0) { GameButtonMenu* buttonMenu = (GameButtonMenu*)this->getChildByTag(SceneGameTagButtonMenu); buttonMenu->buttonPressed(); } // update the other nodes IGNode::update(); }
GLvoid keyboardSpecialCallback(int key, int x, int y, jboolean up) { char* keyString = NULL; switch (key) { case GLUT_KEY_F1: keyString = "F1"; break; case GLUT_KEY_F2: keyString = "F2"; break; case GLUT_KEY_F3: keyString = "F3"; break; case GLUT_KEY_F4: keyString = "F4"; break; case GLUT_KEY_F5: keyString = "F5"; break; case GLUT_KEY_F6: keyString = "F6"; break; case GLUT_KEY_F7: keyString = "F7"; break; case GLUT_KEY_F8: keyString = "F8"; break; case GLUT_KEY_F9: keyString = "F9"; break; case GLUT_KEY_F10: keyString = "F10"; break; case GLUT_KEY_F11: keyString = "F11"; break; case GLUT_KEY_F12: keyString = "F12"; break; case GLUT_KEY_LEFT: keyString = "LEFT"; break; case GLUT_KEY_RIGHT: keyString = "RIGHT"; break; case GLUT_KEY_UP: keyString = "UP"; break; case GLUT_KEY_DOWN: keyString = "DOWN"; break; } if (keyString != NULL ) { pressKey(keyString, up); } }
TEST_F(TestVendorInScene, movesDownWhenDownDirectionPressedAndInLeftAisle) { sut->setX(constantValues::LEFT_VERTICAL_AISLE_LOCATION); QPointF originalPos = sut->pos(); pressKey(Qt::Key_Down); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.x(), updatedPos.x()); EXPECT_EQ(originalPos.y() + constantValues::MOVEMENT_AMOUNT, updatedPos.y()); }
TEST_F(TestVendorInScene, movesLeftWhenLeftDirectionPressedAndInTopAisle) { sut->setY(constantValues::TOP_HORIZONTAL_AISLE_LOCATION); QPointF originalPos = sut->pos(); pressKey(Qt::Key_Left); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.x() - constantValues::MOVEMENT_AMOUNT, updatedPos.x()); EXPECT_EQ(originalPos.y(), updatedPos.y()); }
TEST_F(TestVendorInScene, movesRightWhenRightDirectionPressedAndInBottomAisle) { sut->setY(constantValues::BOTTOM_HORIZONTAL_AISLE_LOCATION); QPointF originalPos = sut->pos(); pressKey(Qt::Key_Right); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.y(), updatedPos.y()); EXPECT_EQ(originalPos.x() + constantValues::MOVEMENT_AMOUNT, updatedPos.x()); }
TEST_F(TestVendorInScene, movesUpWhenUpDirectionPressedAndInRightAisle) { sut->setX(constantValues::RIGHT_VERTICAL_AISLE_LOCATION); QPointF originalPos = sut->pos(); pressKey(Qt::Key_Up); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.y() - constantValues::MOVEMENT_AMOUNT, updatedPos.y()); EXPECT_EQ(originalPos.x(), updatedPos.x()); }
TEST_F(TestVendorInScene, doesNotMoveUpWhenNotInOneOfTheVerticalAisles) { QPointF originalPos = sut->pos(); ASSERT_NE(constantValues::LEFT_VERTICAL_AISLE_LOCATION, originalPos.x()); ASSERT_NE(constantValues::RIGHT_VERTICAL_AISLE_LOCATION, originalPos.x()); pressKey(Qt::Key_Up); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.x(), updatedPos.x()); EXPECT_EQ(originalPos.y(), updatedPos.y()); }
void Macro::playMacro(){ int i; i = 0; while(macro[i] != 0) //reads off first 100 keys { qDebug() << macro[i]; pressKey(macro[i]); Sleep(delay); i++;//keys are stored as ascii integers; see www.asciitable.com } playing = 0; }
void keyMouse::applyKeys(){ INPUT eventPress = {0}; INPUT eventRelease = {0}; bool send = false; //Check if there is anything new to press for(std::vector<std::string>::size_type i = 0; i != buttons.size(); i++) { //if in buttons and not in buttonsOld press it if(!(std::find(buttonsOld.begin(), buttonsOld.end(), buttons[i]) != buttonsOld.end())){ // buttonsOld does not contain buttons[i] so press the button if(buttons[i].find("KEY") != std::string::npos){ pressKey(eventPress, bmap[buttons[i]]); send = true; }else if(buttons[i].find("MOUSE") != std::string::npos){ pressMouse(eventPress, bmap[buttons[i]]); send = true; }else if(buttons[i].find("MOTION") != std::string::npos){ send = false; processMotionPress(buttons[i]); } if(send == true){ SendInput( 1, &eventPress, sizeof( eventPress ) ); } } } //Check if anything that was pressed last time is now unpressed for(std::vector<std::string>::size_type i = 0; i != buttonsOld.size(); i++) { //if in buttonsOld and not in buttons release it if( !(std::find(buttons.begin(), buttons.end(), buttonsOld[i]) != buttons.end())) { // buttons does not contain buttonsOld[i] so release the button press if(buttonsOld[i].find("KEY") != std::string::npos){ releaseKey(eventRelease, bmap[buttonsOld[i]]); send = true; // std::cout << " ReleaseKey: " << buttonsOld[i] << "\n"; }else if(buttonsOld[i].find("MOUSE") != std::string::npos){ releaseMouse(eventRelease, bmap[buttonsOld[i]]); send = true; //std::cout << " ReleaseMouse: " << buttonsOld[i] << "\n"; }else if(buttonsOld[i].find("MOTION") != std::string::npos){ send = false; processMotionRelease(buttonsOld[i]); } if(send == true){ SendInput( 1, &eventRelease, sizeof( eventRelease ) ); } } } buttonsOld = buttons; //clear the vector buttons.clear(); }
TEST_F(TestVendorInScene, doesNotMoveRightWhenNotInOneOfTheHorizontalAisles) { sut->setY(constantValues::TOP_HORIZONTAL_AISLE_LOCATION + constantValues::MOVEMENT_AMOUNT); QPointF originalPos = sut->pos(); ASSERT_NE(constantValues::TOP_HORIZONTAL_AISLE_LOCATION, originalPos.y()); ASSERT_NE(constantValues::BOTTOM_HORIZONTAL_AISLE_LOCATION, originalPos.y()); pressKey(Qt::Key_Right); QPointF updatedPos = sut->pos(); EXPECT_EQ(originalPos.x(), updatedPos.x()); EXPECT_EQ(originalPos.y(), updatedPos.y()); }
void Keyboard::onEvent(const SDL_Event& event) { if (event.type == SDL_KEYDOWN) { if (!event.key.repeat) { pressKey(event.key.keysym.scancode); } } if (event.type == SDL_KEYUP) { releaseKey(event.key.keysym.scancode); } }
TEST_F(TestVendorInScene, dropsFoodToRightWhenRightIsPressedAndInVerticalAisle) { ASSERT_EQ(1, scene.items().count()); sut->setY(constantValues::LEFT_VERTICAL_AISLE_LOCATION); QPointF vendorPosition = sut->pos(); QRect selectionRect(vendorPosition.x() + sut->boundingRect().width(), vendorPosition.y(), 10,10); ASSERT_EQ(0, scene.items(selectionRect, Qt::IntersectsItemShape).count()); pressKey(Qt::Key_Right); EXPECT_EQ(1, scene.items(selectionRect, Qt::IntersectsItemShape).count()); EXPECT_EQ(2, scene.items().count()); }
TEST_F(TestVendorInScene, dropsFoodToLeftWhenLeftIsPressedAndInVerticalAisle) { ASSERT_EQ(1, scene.items().count()); sut->setY(constantValues::LEFT_VERTICAL_AISLE_LOCATION); QPointF vendorPosition = sut->pos(); int foodWidth = 20; // can we get this programatically in the test??? QRect selectionRect(vendorPosition.x() - foodWidth, vendorPosition.y(), 10,10); EXPECT_EQ(0, scene.items(selectionRect, Qt::IntersectsItemShape).count()); pressKey(Qt::Key_Left); EXPECT_EQ(1, scene.items(selectionRect, Qt::IntersectsItemShape).count()); EXPECT_EQ(2, scene.items().count()); }
void KeyTracker::keyEvent(QKeyEvent *event) { switch (event->type()) { case QEvent::KeyPress: pressKey(event->key()); setModifiers(event->modifiers()); break; case QEvent::KeyRelease: releaseKey(event->key()); break; default: break; } }
TEST_F( Ginga, media_dinamic_transparency1 ) { ASSERT_TRUE( play("media/transparency/dinamic_transparency1.ncl") ); ASSERT_TRUE( compareTo("blue720x576") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("transparency50%") ); }
TEST_F( Ginga, media_dinamic_fontStyle1 ) { ASSERT_TRUE( play("media/fontStyle/dinamic_fontStyle1.ncl") ); ASSERT_TRUE( compareTo("standardText") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("standardText_italic") ); }
static void postKeyMessage(int x, int y, unsigned int msg) { SetForegroundWindow(windowFromPoint(x, y)); switch(msg) { case 'a' : pressKey(A); break; case 'b' : pressKey(B); break; case 'A' : pressShifted(A);break; case '1' : pressKey(ONE); break; case '2' : pressKey(TWO); break; case '3' : pressKey(THREE); break; case '4' : pressKey(FOUR); break; case '5' : pressKey(FIVE); break; case '6' : pressKey(SIX); break; case '7' : pressKey(SEVEN); break; case '8' : pressKey(EIGHT); break; case '9' : pressKey(NINE); break; case '0' : pressKey(ZERO); break; case '\t' : pressKey(TAB); break; case '\n' : pressKey(ENTER); break; } }
TEST_F( Ginga, media_dinamic_bottom14 ) { ASSERT_TRUE( play("media/bottom/dinamic_bottom14.ncl") ); ASSERT_TRUE( compareTo("blue720x576") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("blue720x288_black720x288") ); }
TEST_F( Ginga, media_dinamic_height8 ) { ASSERT_TRUE( play("media/height/dinamic_height8.ncl") ); ASSERT_TRUE( compareTo("blue720x288_black720x288") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("blue720x288_black720x288") ); }
static void pressShifted(unsigned int key) { keybd_event(SHIFT, 0, 0, 0); pressKey(key); keybd_event(SHIFT, 0, KEYEVENTF_KEYUP, 0); }
TEST_F( Ginga, media_dinamic_visible1 ) { ASSERT_TRUE( play("media/visible/dinamic_visible1.ncl") ); ASSERT_TRUE( compareTo("blue720x576") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("black720x576") ); }
TEST_F( Ginga, media_dinamic_height15 ) { ASSERT_TRUE( play("media/height/dinamic_height15.ncl") ); ASSERT_TRUE( compareTo("blue720x576") ); ASSERT_TRUE( pressKey( ::util::key::red )); ASSERT_TRUE( compareTo("blue720x576") ); }
// addExtendedChar //-------------------------------------------------------------------------- void cInputField::addExtendedChar(int newExtendedChar) { pressKey(newExtendedChar); // Process the extendedChar accordingly. switch (newExtendedChar) { case SDLK_HOME: { cursorPos = 0; } break; case SDLK_LEFT: { if(cursorPos>0) cursorPos--; } break; case SDLK_RIGHT: { size_t length = strlen(destString); ++cursorPos; if ( cursorPos >= maxCharCount ) { cursorPos = maxCharCount - 1; } else if ( cursorPos > length ) { cursorPos = length; } } break; case SDLK_END: { cursorPos = strlen(destString); if (cursorPos >= maxCharCount) { cursorPos = maxCharCount - 1; } } break; case SDLK_INSERT: { insertMode^=1; } break; case SDLK_DELETE: { if (cursorPos == strlen(destString)) { break; } memcpy(destString + cursorPos, destString + cursorPos + 1, strlen(destString + cursorPos + 1) + 1); } break; case SDLK_BACKSPACE: { if (cursorPos >= 1) { int byteCount = strlen(destString + cursorPos); // Only do this if we are not at the end of the string. if (byteCount > 0) { memcpy(destString + cursorPos - 1, destString + cursorPos, byteCount); } cursorPos--; destString[cursorPos + byteCount] = '\0'; } } break; case SDLK_KP_ENTER: case SDLK_RETURN: break; default: break; } if(textaction != 0) textaction(this); } // addExtendedChar
void InputManager::updateKeys() { if (glfwGetKey(m_window, GLFW_KEY_0) == GLFW_PRESS) { pressKey(KEYS::NUM_0); } else { releaseKey(KEYS::NUM_1); } if (glfwGetKey(m_window, GLFW_KEY_1) == GLFW_PRESS) { pressKey(KEYS::NUM_1); } else { releaseKey(KEYS::NUM_1); } if (glfwGetKey(m_window, GLFW_KEY_2) == GLFW_PRESS) { pressKey(KEYS::NUM_2); } else { releaseKey(KEYS::NUM_2); } if (glfwGetKey(m_window, GLFW_KEY_3) == GLFW_PRESS) { pressKey(KEYS::NUM_3); } else { releaseKey(KEYS::NUM_3); } if (glfwGetKey(m_window, GLFW_KEY_4) == GLFW_PRESS) { pressKey(KEYS::NUM_4); } else { releaseKey(KEYS::NUM_4); } if (glfwGetKey(m_window, GLFW_KEY_5) == GLFW_PRESS) { pressKey(KEYS::NUM_5); } else { releaseKey(KEYS::NUM_5); } if (glfwGetKey(m_window, GLFW_KEY_6) == GLFW_PRESS) { pressKey(KEYS::NUM_6); } else { releaseKey(KEYS::NUM_6); } if (glfwGetKey(m_window, GLFW_KEY_7) == GLFW_PRESS) { pressKey(KEYS::NUM_7); } else { releaseKey(KEYS::NUM_7); } if (glfwGetKey(m_window, GLFW_KEY_8) == GLFW_PRESS) { pressKey(KEYS::NUM_8); } else { releaseKey(KEYS::NUM_8); } if (glfwGetKey(m_window, GLFW_KEY_9) == GLFW_PRESS) { pressKey(KEYS::NUM_9); } else { releaseKey(KEYS::NUM_9); } if (glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS) { pressKey(KEYS::A); } else { releaseKey(KEYS::A); } if (glfwGetKey(m_window, GLFW_KEY_B) == GLFW_PRESS) { pressKey(KEYS::B); } else { releaseKey(KEYS::B); } if (glfwGetKey(m_window, GLFW_KEY_C) == GLFW_PRESS) { pressKey(KEYS::C); } else { releaseKey(KEYS::C); } if (glfwGetKey(m_window, GLFW_KEY_D) == GLFW_PRESS) { pressKey(KEYS::D); } else { releaseKey(KEYS::D); } if (glfwGetKey(m_window, GLFW_KEY_E) == GLFW_PRESS) { pressKey(KEYS::E); } else { releaseKey(KEYS::E); } if (glfwGetKey(m_window, GLFW_KEY_F) == GLFW_PRESS) { pressKey(KEYS::F); } else { releaseKey(KEYS::F); } if (glfwGetKey(m_window, GLFW_KEY_G) == GLFW_PRESS) { pressKey(KEYS::G); } else { releaseKey(KEYS::G); } if (glfwGetKey(m_window, GLFW_KEY_H) == GLFW_PRESS) { pressKey(KEYS::H); } else { releaseKey(KEYS::H); } if (glfwGetKey(m_window, GLFW_KEY_I) == GLFW_PRESS) { pressKey(KEYS::I); } else { releaseKey(KEYS::I); } if (glfwGetKey(m_window, GLFW_KEY_J) == GLFW_PRESS) { pressKey(KEYS::J); } else { releaseKey(KEYS::J); } if (glfwGetKey(m_window, GLFW_KEY_K) == GLFW_PRESS) { pressKey(KEYS::K); } else { releaseKey(KEYS::K); } if (glfwGetKey(m_window, GLFW_KEY_L) == GLFW_PRESS) { pressKey(KEYS::L); } else { releaseKey(KEYS::L); } if (glfwGetKey(m_window, GLFW_KEY_M) == GLFW_PRESS) { pressKey(KEYS::M); } else { releaseKey(KEYS::M); } if (glfwGetKey(m_window, GLFW_KEY_N) == GLFW_PRESS) { pressKey(KEYS::N); } else { releaseKey(KEYS::N); } if (glfwGetKey(m_window, GLFW_KEY_O) == GLFW_PRESS) { pressKey(KEYS::O); } else { releaseKey(KEYS::O); } if (glfwGetKey(m_window, GLFW_KEY_P) == GLFW_PRESS) { pressKey(KEYS::P); } else { releaseKey(KEYS::P); } if (glfwGetKey(m_window, GLFW_KEY_Q) == GLFW_PRESS) { pressKey(KEYS::Q); } else { releaseKey(KEYS::Q); } if (glfwGetKey(m_window, GLFW_KEY_R) == GLFW_PRESS) { pressKey(KEYS::R); } else { releaseKey(KEYS::R); } if (glfwGetKey(m_window, GLFW_KEY_S) == GLFW_PRESS) { pressKey(KEYS::S); } else { releaseKey(KEYS::S); } if (glfwGetKey(m_window, GLFW_KEY_T) == GLFW_PRESS) { pressKey(KEYS::T); } else { releaseKey(KEYS::T); } if (glfwGetKey(m_window, GLFW_KEY_U) == GLFW_PRESS) { pressKey(KEYS::U); } else { releaseKey(KEYS::U); } if (glfwGetKey(m_window, GLFW_KEY_V) == GLFW_PRESS) { pressKey(KEYS::V); } else { releaseKey(KEYS::V); } if (glfwGetKey(m_window, GLFW_KEY_W) == GLFW_PRESS) { pressKey(KEYS::W); } else { releaseKey(KEYS::W); } if (glfwGetKey(m_window, GLFW_KEY_X) == GLFW_PRESS) { pressKey(KEYS::X); } else { releaseKey(KEYS::X); } if (glfwGetKey(m_window, GLFW_KEY_Y) == GLFW_PRESS) { pressKey(KEYS::Y); } else { releaseKey(KEYS::Y); } if (glfwGetKey(m_window, GLFW_KEY_Z) == GLFW_PRESS) { pressKey(KEYS::Z); } else { releaseKey(KEYS::Z); } if (glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { pressKey(KEYS::ESC); } else { releaseKey(KEYS::ESC); } if (glfwGetKey(m_window, GLFW_KEY_TAB) == GLFW_PRESS) { pressKey(KEYS::TAB); } else { releaseKey(KEYS::TAB); } if (glfwGetKey(m_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) { pressKey(KEYS::LFET_SHIFT); } else { releaseKey(KEYS::LFET_SHIFT); } if (glfwGetKey(m_window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) { pressKey(KEYS::LEFT_COTROL); } else { releaseKey(KEYS::LEFT_COTROL); } if (glfwGetKey(m_window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) { pressKey(KEYS::LEFT_ALT); } else { releaseKey(KEYS::LEFT_ALT); } if (glfwGetKey(m_window, GLFW_KEY_SPACE) == GLFW_PRESS) { pressKey(KEYS::SPACE); } else { releaseKey(KEYS::SPACE); } if (glfwGetKey(m_window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS) { pressKey(KEYS::RIGHT_ALT); } else { releaseKey(KEYS::RIGHT_ALT); } if (glfwGetKey(m_window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) { pressKey(KEYS::RIGHT_CONTROL); } else { releaseKey(KEYS::RIGHT_CONTROL); } if (glfwGetKey(m_window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS) { pressKey(KEYS::RIGHT_SHIFT); } else { releaseKey(KEYS::RIGHT_SHIFT); } if (glfwGetKey(m_window, GLFW_KEY_ENTER) == GLFW_PRESS) { pressKey(KEYS::ENTER); } else { releaseKey(KEYS::ENTER); } if (glfwGetKey(m_window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { pressKey(KEYS::BACKSPACE); } else { releaseKey(KEYS::BACKSPACE); } if (glfwGetKey(m_window, GLFW_KEY_UP) == GLFW_PRESS) { pressKey(KEYS::UP); } else { releaseKey(KEYS::UP); } if (glfwGetKey(m_window, GLFW_KEY_DOWN) == GLFW_PRESS) { pressKey(KEYS::DOWN); } else { releaseKey(KEYS::DOWN); } if (glfwGetKey(m_window, GLFW_KEY_LEFT) == GLFW_PRESS) { pressKey(KEYS::LEFT); } else { releaseKey(KEYS::LEFT); } if (glfwGetKey(m_window, GLFW_KEY_RIGHT) == GLFW_PRESS) { pressKey(KEYS::RIGHT); } else { releaseKey(KEYS::RIGHT); } if (glfwGetKey(m_window, GLFW_KEY_F1) == GLFW_PRESS) { pressKey(KEYS::F1); } else { releaseKey(KEYS::F1); } if (glfwGetKey(m_window, GLFW_KEY_F2) == GLFW_PRESS) { pressKey(KEYS::F2); } else { releaseKey(KEYS::F2); } if (glfwGetKey(m_window, GLFW_KEY_F3) == GLFW_PRESS) { pressKey(KEYS::F3); } else { releaseKey(KEYS::F3); } if (glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) { pressKey(KEYS::MOUSE_LEFT); } else { releaseKey(KEYS::MOUSE_LEFT); } if (glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) { pressKey(KEYS::MOUSE_MIDDLE); } else { releaseKey(KEYS::MOUSE_MIDDLE); } if (glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) { pressKey(KEYS::MOUSE_RIGHT); } else { releaseKey(KEYS::MOUSE_RIGHT); } }
void KeyMap::PCtoX(BYTE virtKey, DWORD keyData, ClientConnection* clientCon) { bool down = ((keyData & 0x80000000) == 0); bool extended = ((keyData & 0x1000000) != 0); bool repeated = ((keyData & 0xc0000000) == 0x40000000); UINT extVkey = virtKey + (extended ? 256 : 0); // exclude winkey when not scroll-lock if (virtKey==91 || virtKey==92) return; vnclog.Print(8, _T("\nPCtoX: %svirtKey 0x%02x%s%s, keyData 0x%08x\n"), (extended ? _T("extended ") : _T("")), virtKey, (repeated ? _T(" repeated") : _T("")), (down ? _T(" down") : _T(" up")), keyData); // If this is a key release then just send the associated sent KeySym when // this key was pressed if (!down) { vnclog.Print(8, _T("Release the associated KeySym when this VirtKey was pressed\n")); if (downUnicode[extVkey]) { vnclog.Print(8, _T(" 0x%04x (%c): "), downUnicode[extVkey], downUnicode[extVkey]); downUnicode[extVkey] = NULL; } else { vnclog.Print(8, _T(" Control character: ")); } releaseKey(clientCon, extVkey); vnclog.Print(8, _T("\n")); GetKeyboardState(KBKeysState); if (!((KBKeysState[VK_MENU] & 0x80) && (KBKeysState[VK_CONTROL] & 0x80))) { if (storedDeadChar && reset) { reset=false; keybd_event(VK_SPACE, 0, 0, 0); keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0); } } return; } // We try to look it up in our key table // Look up the desired code in the keyMap table try to find the exact match according to // the extended flag, then try the opposite of the extended flag CARD32 foundXCode = XK_VoidSymbol; bool exactMatched = false; vnclog.Print(8, _T("Looking in key table ")); for (UINT i = 0; i < (sizeof(keyMap) / sizeof(vncKeyMapping_t)); i++) { if (keyMap[i].WinCode == virtKey) { foundXCode = keyMap[i].XCode; if (extended == keyMap[i].extVK) { exactMatched = true; break; } } } if (foundXCode != XK_VoidSymbol) { vnclog.Print(8, _T("-> keyMap gives (from %s extended flag) KeySym %u (0x%08x)\n"), (exactMatched ? _T("matched") : _T("opposite")), foundXCode, foundXCode); pressKey(clientCon, extVkey, foundXCode); vnclog.Print(8, _T("\n")); return; } else { vnclog.Print(8, _T("-> not in special keyMap\n")); } // Under CE, we're not so concerned about this bit because we handle a WM_CHAR message later #ifndef UNDER_CE GetKeyboardState(KBKeysState); ModifierKeyReleaser lctrl(clientCon, VK_CONTROL, 0); ModifierKeyReleaser lalt(clientCon, VK_MENU, 0); ModifierKeyReleaser ralt(clientCon, VK_MENU, 1); if ((KBKeysState[VK_MENU] & 0x80) && (KBKeysState[VK_CONTROL] & 0x80)) { // This is a Ctrl-Alt (AltGr) key on international keyboards (= LCtrl-RAlt) // Ex. Ctrl-Alt-Q gives '@' on German keyboards vnclog.Print(8, _T("Ctrl-Alt pressed:\n")); // We must release Control and Alt (AltGr) if they were both pressed, so the character // is seen without them by the VNC server // We don't release the Right Control; this allows German users // to use it for doing Ctrl-AltGr-x, e.g. Ctl-@, etc lctrl.release(downKeysym); lalt.release(downKeysym); ralt.release(downKeysym); } else { // This is not a Ctrl-Alt (AltGr) key vnclog.Print(8, _T("Ctrl-Alt not pressed, fake release any Ctrl key\n")); // There are no KeySym corresponding to control characters, e.g. Ctrl-F // The server has already known whether the Ctrl key is pressed from the previouse key event // So we are interested in the key that would be there if the Ctrl key were not pressed KBKeysState[VK_CONTROL] = KBKeysState[VK_LCONTROL] = KBKeysState[VK_RCONTROL] = 0; } int ret; if (storedDeadChar) { SHORT virtDeadKey; BYTE prevModifierState = 0; vnclog.Print(8, _T("[Storing base character modifier(s)]\n")); StoreModifier(&prevModifierState, KBKeysState); virtDeadKey = VkKeyScanW(storedDeadChar); vnclog.Print(8, _T("[A dead key was stored, restoring the dead key state:") _T(" 0x%02x (%c) using virtDeadKey 0x%02x] "), storedDeadChar, storedDeadChar, virtDeadKey); SetModifier(HIBYTE(virtDeadKey), KBKeysState); vnclog.Print(8, _T("\n")); ToUnicode((virtDeadKey & 0xff), 0, KBKeysState, ucsChar, (sizeof(ucsChar) / sizeof(WCHAR)), 0); vnclog.Print(8, _T("[Restoring base character modifier(s)] ")); SetModifier(prevModifierState, KBKeysState); vnclog.Print(8, _T("\n")); storedDeadChar = 0; ret = ToUnicode(virtKey, 0, KBKeysState, ucsChar, (sizeof(ucsChar) / sizeof(WCHAR)), 0); } else ret = ToUnicode(virtKey, 0, KBKeysState, ucsChar, (sizeof(ucsChar) / sizeof(WCHAR)), 0); if (ucsChar[0]==8364) { //euro // return; } if (ret < 0 || ret==2) { // It is a dead key vnclog.Print(8, _T("ToUnicode returns dead key: 0x%02x (%c) "), *ucsChar, *ucsChar); if (sendDeadKey) { // We try to look it up in our dead key table // Look up the desired code in the deadKeyMap table foundXCode = XK_VoidSymbol; for (UINT i = 0; i < (sizeof(deadKeyMap) / sizeof(vncDeadKeyMapping_t)); i++) { if (deadKeyMap[i].deadKeyChar == *ucsChar) { foundXCode = deadKeyMap[i].XCode; break; } } if (foundXCode != XK_VoidSymbol) { vnclog.Print(8, _T("-> deadKeyMap gives KeySym %u (0x%08x)\n"), foundXCode, foundXCode); pressKey(clientCon, extVkey, foundXCode); } else { vnclog.Print(8, _T("-> not in deadKeyMap\n")); } } else { storedDeadChar = *ucsChar; reset=true; vnclog.Print(8, _T("-> Store the dead key state, wait for next key-stroke\n")); } FlushDeadKey(KBKeysState); } else if (ret > 0) { vnclog.Print(8, _T("ToUnicode returns %d character(s):\n"), ret); for (int i = 0; i < ret; i++) { CARD32 xChar = UCS2X(*(ucsChar+i)); if (xChar != XK_VoidSymbol) { downUnicode[extVkey] = *(ucsChar+i); pressKey(clientCon, extVkey, xChar); } } } else { vnclog.Print(8, _T("No character is generated by this key event\n")); } #endif vnclog.Print(8, _T("\n")); };