public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed) { var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted); bool thisKeyValid = (c != '\0' && !altPressed && !ctlPressed && !logoPressed); if (!thisKeyValid) { // If this isn't valid, reset the previously memorised key. _LastChar = '\0'; return; } // If this keypress corresponds to a typable character and no modifier keys are pressed and the last character is valid: transpose them. if (_LastChar != '\0') { // Delete the two characters. output.KeyPress(KeyboardKey.BackSpace); output.KeyPress(KeyboardKey.BackSpace); // Echo them in reverse order. output.KeyPressWithModifier(KeyboardTables.CharToKeyStroke(c)); output.KeyPressWithModifier(KeyboardTables.CharToKeyStroke(_LastChar)); // That's the end of this fiddle. _IsComplete = true; return; } // Memorise the key for next call. _LastChar = c; }
public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed) { // Ensure the phrase is inserted at the end of a sentence or paragraph. bool atEndOfSentence = (thisKeyPress == KeyboardKey.Space) && Array.IndexOf(KeyboardTables.EndOfSentenceCharacters, _LastLetterPressed) != -1; if (atEndOfSentence) { // Actually insert the phrase!! var s = _Phrases[_SelectedPhrase]; for (int i = 0; i < s.Length; i++) { var keyStroke = KeyboardTables.CharToKeyStroke(s[i]); output.KeyPressWithModifier(keyStroke); } // Append a space. if (s[s.Length - 1] != ' ') { output.KeyPress(KeyboardKey.Space); } // Mark completion. _IsComplete = true; } else { // Capture the last keypress as a character. var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted); if (c != (char)0) { _LastLetterPressed = c; } } }
public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed) { // If this keypress corresponds to a typable character and no modifier keys are pressed: duplicate it. var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted); if (c != '\0' && !altPressed && !ctlPressed && !logoPressed) { var keyStroke = KeyboardTables.CharToKeyStroke(c); output.KeyPressWithModifier(keyStroke); _IsComplete = true; } }
public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed) { // If this keypress corresponds to a typable character and no modifier keys are pressed: insert a random one. if (!altPressed && !ctlPressed && !logoPressed && KeyboardTables.KeyToChar(thisKeyPress, isShifted) != '\0') { var charTable = isShifted ? KeyboardTables.ShiftedKeyToCharTable : KeyboardTables.KeyToCharTable; var idx = _Random.Next(charTable.Length - 1); char theChosenKey = charTable[idx]; if (theChosenKey == '\0') { // Didn't randomly choose a valid key: wait for next press. return; } // Delete previous key and echo the randomly chosen one. var keyStroke = KeyboardTables.CharToKeyStroke(theChosenKey); output.KeyPressWithModifier(keyStroke); _IsComplete = true; } }