// does the same as KeyIsPressed, but automatically releases the key as well.. bool KeyIsPressedR (SDLKey key) { bool ret; keyboard_update(); ret = key_pressed[key]; ReleaseKey (key); return (ret); }
// does the same as KeyIsPressed, but automatically releases the key as well.. bool KeyIsPressedR (SDLKey key) { bool ret; ret = KeyIsPressed (key); ReleaseKey (key); return (ret); }
// Build the SAM keyboard matrix from the current PC state void SetSamKeyState () { // No SAM keys are pressed initially ReleaseAllSamKeys(); // Set any SIP selection on the SAM keyboard if (nSipKey >= 0 && nSipKey != SK_NONE) PressSamKey(nSipKey); if (nSipMods & SMOD_SHIFT) PressSamKey(SK_SHIFT); if (nSipMods & SMOD_SYMBOL) PressSamKey(SK_SYMBOL); if (nSipMods & SMOD_CONTROL) PressSamKey(SK_CONTROL); // If the control pad or hardware keys are pressed, activate the appropriate SAM key for (int i = 0 ; i < sizeof(anHwKeys)/sizeof(anHwKeys[0]) ; i++) { if (IsPressed(anHwKeys[i])) PressSamKey(anKeyMap[i]); } // Left and right shift keys are equivalent, and also complementary! bool fShiftToggle = IsPressed(VK_LSHIFT) && IsPressed(VK_RSHIFT); // Process the key combinations required for the mode we're in switch (GetOption(keymapping)) { // SAM keys case 1: ProcessKeyTable(asSamSymbols); ProcessKeyTable(asSamMappings); break; // Spectrum mappings case 2: ProcessKeyTable(asSpectrumSymbols); ProcessKeyTable(asSpectrumMappings); break; } // Toggle shift if both shift keys are down to allow shifted versions of keys that are // shifted on the PC but unshifted on the SAM if (fShiftToggle) ReleaseKey(VK_SHIFT); // Process the simple key mappings ProcessKeyTable(asSamKeys); // Update the SIP if it may have changed if (fSipDirty) { InvalidateRect(g_hwndSIP, NULL, FALSE); fSipDirty = false; } }
void ReadKeyboard () { // Make a copy of the master key table with the real keyboard states memcpy(afKeyStates, afKeys, sizeof(afKeyStates)); // Left-Alt can optionally be used as the SAM Cntrl key if (GetOption(altforcntrl) && IsPressed(VK_LMENU)) { ReleaseKey(VK_LMENU); PressKey(VK_RCONTROL); } // AltGr can optionally be used for SAM Edit if (GetOption(altgrforedit) && IsPressed(VK_RMENU)) { // Release AltGr and press the context menu key (also used for SAM Edit) ReleaseKey(VK_RMENU); PressKey(VK_APPS); // Also release Ctrl and Alt, which is how AltGr often behaves ReleaseKey(VK_LCONTROL); ReleaseKey(VK_LMENU); } }
CKeyPair::~CKeyPair(void) { if (m_hCryptKey != NULL) ReleaseKey(); }
void JGE::Run() { static const int keyCodeList[] = { PSP_CTRL_SELECT, // Select button. PSP_CTRL_START, // Start button. PSP_CTRL_UP, // Up D-Pad button. PSP_CTRL_RIGHT, // Right D-Pad button. PSP_CTRL_DOWN, // Down D-Pad button. PSP_CTRL_LEFT, // Left D-Pad button. PSP_CTRL_LTRIGGER, // Left trigger. PSP_CTRL_RTRIGGER, // Right trigger. PSP_CTRL_TRIANGLE, // Triangle button. PSP_CTRL_CIRCLE, // Circle button. PSP_CTRL_CROSS, // Cross button. PSP_CTRL_SQUARE, // Square button. PSP_CTRL_HOLD, // Hold button. }; u64 curr; long long int nextInput = 0; u64 lastTime; u32 oldButtons; u32 veryOldButtons; u32 gTickFrequency = sceRtcGetTickResolution(); sceRtcGetCurrentTick(&lastTime); oldButtons = veryOldButtons = 0; while (!mDone) { if (!mPaused) { sceRtcGetCurrentTick(&curr); float dt = (curr - lastTime) / (float)gTickFrequency; mDeltaTime = dt; sceCtrlPeekBufferPositive(&gCtrlPad, 1); for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) { if (keyCodeList[i] & gCtrlPad.Buttons) { if (!(keyCodeList[i] & oldButtons)) HoldKey(keyCodeList[i]); } else if (keyCodeList[i] & oldButtons) ReleaseKey(keyCodeList[i]); } oldButtons = gCtrlPad.Buttons; Update(dt); Render(); if (mDebug) { if (strlen(mDebuggingMsg)>0) { pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf(mDebuggingMsg); } } veryOldButtons = gCtrlPad.Buttons; } else sceKernelDelayThread(1); lastTime = curr; } }
STDMETHODIMP CSoftKeyboard::PressAndReleaseKeys( BSTR bstrKeyStrokes) /*++ Routine Description: Implement the PressAndRelease method for the interface ISoftKeyboard. This simulate a key stroke for a UNICODE character Synchronization: None Arguments: bstrKeyStrokes - Keystrokes to be simulated Return Value: E_FAIL Could not generate a sequence of keycodes to simulate a keystroke. E_INVALIDARG Invalid keystroke length. S_OK Success. --*/ { HRESULT hr = S_OK; UINT nUnits = 0; KBD_KEYCODE* pKeyCodes = NULL; UINT nSize = SysStringLen(bstrKeyStrokes); // Check if string is not NULL IfFalseHrGo(nSize != 0, E_INVALIDARG); // Check is Translator property is set IfFalseHrGo(NULL != m_piSoftKbdTranslator, E_UNEXPECTED); hr = m_piSoftKbdTranslator->TranslateString2Keycodes(nSize, bstrKeyStrokes, &nUnits, &pKeyCodes); IfFailHrGo(hr); // Go through returned sequence and queue it for processing for(UINT i = 0; i < nUnits; i++) { // Call PressKey method if (KEY_MAKE == pKeyCodes[i].ucFlag) { IfFailHrGo(PressKey(pKeyCodes[i].KeyCode)); } // Call ReleaseKey method else if (KEY_BREAK == pKeyCodes[i].ucFlag) { IfFailHrGo(ReleaseKey(pKeyCodes[i].KeyCode)); } // Call HitKeyOnce method else if ((KEY_BREAK | KEY_MAKE) == pKeyCodes[i].ucFlag) { IfFailHrGo(HitKeyOnce(pKeyCodes[i].KeyCode)); } // Should never hit this code, but check anyway else { IfFailHrGo(E_FAIL); } } Exit: m_pMalloc->Free(pKeyCodes); return hr; } // CSoftKeyboard::PressAndReleaseKeys
// Process more complicated key combinations void ProcessKeyTable (COMBINATION_KEY* asKeys_) { short nShifts = 0; if (IsPressed(VK_SHIFT)) nShifts |= MOD_SHIFT; if (IsPressed(VK_LCONTROL)) nShifts |= MOD_LCTRL; if (IsPressed(VK_LMENU)) nShifts |= MOD_LALT; if (IsPressed(VK_RMENU)) nShifts |= MOD_RALT; // Have the shift states changed while a combo is in progress? if (nComboModifiers != MOD_NONE && nComboModifiers != nShifts) { // If the combo key is still pressed, start the timer running to re-press it as we're about to release it if (IsPressed(nComboKey)) { TRACE("Starting combo timer\n"); dwComboTime = OSD::GetTime(); } // We're done with the shift state now, so clear it to prevent the time getting reset nComboModifiers = MOD_NONE; } // Combo unpress timer active? if (dwComboTime) { TRACE("Combo timer active\n"); // If we're within the threshold, ensure the key remains released if ((OSD::GetTime() - dwComboTime) < 250) { TRACE("Releasing combo key\n"); ReleaseKey(nComboKey); } // Otherwise clear the expired timer else { TRACE("Combo timer expired\n"); dwComboTime = 0; } } for (int i = 0 ; asKeys_[i].nSamKey != SK_NONE; i++) { if (IsPressed(asKeys_[i].nKey) && asKeys_[i].nMods == nShifts) { // Release the PC keys used for the key combination ReleaseKey(asKeys_[i].nKey); if (nShifts & MOD_SHIFT) ToggleKey(VK_SHIFT); if (nShifts & MOD_LCTRL) ToggleKey(VK_LCONTROL); if (nShifts & MOD_LALT) { ToggleKey(VK_LMENU); ReleaseKey(VK_RCONTROL); } // Press the SAM key(s) required to generate the symbol PressSamKey(asKeys_[i].nSamKey); PressSamKey(asKeys_[i].nSamMods); // Remember the key involved with the shifted state for a combo nComboKey = asKeys_[i].nKey; nComboModifiers = nShifts; } } }