// Sends a single key //##ModelId=474D3026003F void CSendKeys::SendKey(WORD MKey, WORD NumTimes, bool GenDownMsg) { // Send appropriate shift keys associated with the given VKey if (BitSet(HIBYTE(MKey), VKKEYSCANSHIFTON)) SendKeyDown(VK_SHIFT, 1, false); if (BitSet(HIBYTE(MKey), VKKEYSCANCTRLON)) SendKeyDown(VK_CONTROL, 1, false); if (BitSet(HIBYTE(MKey), VKKEYSCANALTON)) SendKeyDown(VK_MENU, 1, false); // Send the actual VKey SendKeyDown(LOBYTE(MKey), NumTimes, GenDownMsg, true); // toggle up shift keys if (BitSet(HIBYTE(MKey), VKKEYSCANSHIFTON)) SendKeyUp(VK_SHIFT); if (BitSet(HIBYTE(MKey), VKKEYSCANCTRLON)) SendKeyUp(VK_CONTROL); if (BitSet(HIBYTE(MKey), VKKEYSCANALTON)) SendKeyUp(VK_MENU); }
void GLUTGUI::Handle_Click(int button,int state,int x,int y) { int clickModifiers = glutGetModifiers(); if(clickModifiers & GLUT_ACTIVE_CTRL) SendKeyDown("control"); else SendKeyUp("control"); if(clickModifiers & GLUT_ACTIVE_SHIFT) SendKeyDown("shift"); else SendKeyUp("shift"); if(clickModifiers & GLUT_ACTIVE_ALT) SendKeyDown("alt"); else SendKeyUp("alt"); SendMouseClick(button,1-state,x,y); }
// Releases all shift keys (keys that can be depressed while other keys are being pressed // If we are in a modifier group this function does nothing //##ModelId=474D3025038B void CSendKeys::PopUpShiftKeys() { if (!m_bUsingParens) { if (m_bShiftDown) SendKeyUp(VK_SHIFT); if (m_bControlDown) SendKeyUp(VK_CONTROL); if (m_bAltDown) SendKeyUp(VK_MENU); if (m_bWinDown) SendKeyUp(VK_LWIN); m_bWinDown = m_bShiftDown = m_bControlDown = m_bAltDown = false; } }
void CSendKeys::AllKeysUp() { for (int key = 0; key < 256; key++) { //If the key is pressed, send a key up, having other keys down interferes with sending ctrl-v, -c and -x short val = GetKeyState(key); if (val & 0x8000) { SendKeyUp(key); //CString cs; //cs.Format(_T("key was down, sending key up %d, value: %d\n"), key, val); //OutputDebugString(cs); } } //Force these to be up, i was having trouble with the right shift key, i think things were //getting confused between the basic shift and lshift, but not sure. SendKeyUp(VK_LSHIFT); SendKeyUp(VK_RSHIFT); SendKeyUp(VK_LCONTROL); SendKeyUp(VK_RCONTROL); SendKeyUp(VK_LMENU); SendKeyUp(VK_RMENU); }
void GLUTGUI::Handle_SpecialUp(int key,int x,int y) { SendKeyUp(special_map(key)); }
void GLUTGUI::Handle_KeypressUp(unsigned char key,int x,int y) { SendKeyUp(string(1,key)); }
void CSendKeys::SendKeyDown(BYTE VKey, WORD NumTimes, bool GenUpMsg, bool bDelay) { WORD Cnt = 0; BYTE ScanCode = 0; bool NumState = false; if (VKey == VK_NUMLOCK) { DWORD dwVersion = ::GetVersion(); for (Cnt=1; Cnt<=NumTimes; Cnt++) { if (bDelay) CarryDelay(); // snippet based on: // http://www.codeproject.com/cpp/togglekeys.asp if (dwVersion < 0x80000000) { ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0); ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } else { // Win98 and later if ( ((DWORD)(HIBYTE(LOWORD(dwVersion))) >= 10) ) { // Define _WIN32_WINNT > 0x0400 // to compile INPUT input[2] = {0}; input[0].type = input[1].type = INPUT_KEYBOARD; input[0].ki.wVk = input[1].ki.wVk = VKey; input[1].ki.dwFlags = KEYEVENTF_KEYUP; ::SendInput(sizeof(input) / sizeof(INPUT), input, sizeof(INPUT)); } // Win95 else { KEYBOARDSTATE_t KeyboardState; NumState = GetKeyState(VK_NUMLOCK) & 1 ? true : false; GetKeyboardState(&KeyboardState[0]); if (NumState) KeyboardState[VK_NUMLOCK] &= ~1; else KeyboardState[VK_NUMLOCK] |= 1; SetKeyboardState(&KeyboardState[0]); } } } return; } // Get scancode ScanCode = LOBYTE(::MapVirtualKey(VKey, 0)); // Send keys for (Cnt=1; Cnt<=NumTimes; Cnt++) { // Carry needed delay ? if (bDelay) CarryDelay(); KeyboardEvent(VKey, ScanCode, IsVkExtended(VKey) ? KEYEVENTF_EXTENDEDKEY : 0); if(m_keyDownDelay > 0) { Sleep(m_keyDownDelay); } if (GenUpMsg) { SendKeyUp(VKey); } } }