// 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); }
// Sends a key string //##ModelId=474D302600AD bool CSendKeys::SendKeys(LPCTSTR KeysString, bool Wait) { WORD MKey, NumTimes; TCHAR KeyString[300] = {0}; bool retval = false; int keyIdx; LPTSTR pKey = (LPTSTR) KeysString; TCHAR ch; m_bWait = Wait; m_bWinDown = m_bShiftDown = m_bControlDown = m_bAltDown = m_bUsingParens = false; while (ch = *pKey) { switch (ch) { // begin modifier group case _TXCHAR('('): m_bUsingParens = true; break; // end modifier group case _TXCHAR(')'): m_bUsingParens = false; PopUpShiftKeys(); // pop all shift keys when we finish a modifier group close break; // ALT key case _TXCHAR('%'): m_bAltDown = true; SendKeyDown(VK_MENU, 1, false); break; // SHIFT key case _TXCHAR('+'): m_bShiftDown = true; SendKeyDown(VK_SHIFT, 1, false); break; // CTRL key case _TXCHAR('^'): m_bControlDown = true; SendKeyDown(VK_CONTROL, 1, false); break; // WINKEY (Left-WinKey) case '@': m_bWinDown = true; SendKeyDown(VK_LWIN, 1, false); break; // enter case _TXCHAR('~'): SendKeyDown(VK_RETURN, 1, true); PopUpShiftKeys(); break; // begin special keys case _TXCHAR('{'): { LPTSTR p = pKey+1; // skip past the beginning '{' size_t t; // find end of close while (*p && *p != _TXCHAR('}')) p++; t = p - pKey; // special key definition too big? if (t > sizeof(KeyString)) return false; // Take this KeyString into local buffer _tcsncpy(KeyString, pKey+1, t); KeyString[t-1] = _TXCHAR('\0'); keyIdx = -1; pKey += t; // skip to next keystring // Invalidate key MKey = INVALIDKEY; // sending arbitrary vkeys? if (_tcsnicmp(KeyString, _T("VKEY"), 4) == 0) { p = KeyString + 4; MKey = _ttoi(p); } else if (_tcsnicmp(KeyString, _T("BEEP"), 4) == 0) { p = KeyString + 4 + 1; LPTSTR p1 = p; DWORD frequency, delay; if ((p1 = _tcsstr(p, _T(" "))) != NULL) { *p1++ = _TXCHAR('\0'); frequency = _ttoi(p); delay = _ttoi(p1); ::Beep(frequency, delay); } } // Should activate a window? else if (_tcsnicmp(KeyString, _T("APPACTIVATE"), 11) == 0) { p = KeyString + 11 + 1; AppActivate(p); } // want to send/set delay? else if (_tcsnicmp(KeyString, _T("DELAY"), 5) == 0) { // Advance to parameters p = KeyString + 5; // set "sleep factor" if (*p == _TXCHAR('=')) m_nDelayAlways = _ttoi(p + 1); // Take number after the '=' character else // set "sleep now" m_nDelayNow = _ttoi(p); } // not command special keys, then process as keystring to VKey else { MKey = StringToVKey(KeyString, keyIdx); // Key found in table if (keyIdx != -1) { NumTimes = 1; // Does the key string have also count specifier? t = _tcslen(KeyNames[keyIdx].keyName); if (_tcslen(KeyString) > t) { p = KeyString + t; // Take the specified number of times NumTimes = _ttoi(p); } if (KeyNames[keyIdx].normalkey) MKey = ::VkKeyScan(KeyNames[keyIdx].VKey); } } // A valid key to send? if (MKey != INVALIDKEY) { SendKey(MKey, NumTimes, true); PopUpShiftKeys(); } } break; // a normal key was pressed default: // Get the VKey from the key MKey = ::VkKeyScan(ch); SendKey(MKey, 1, true); PopUpShiftKeys(); } pKey++; } m_bUsingParens = false; PopUpShiftKeys(); return true; }
void GLUTGUI::Handle_Special(int key,int x,int y) { SendKeyDown(special_map(key)); }
void GLUTGUI::Handle_Keypress(unsigned char key,int x,int y) { SendKeyDown(string(1,key)); }