示例#1
0
        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;
        }
示例#2
0
        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;
                }
            }
        }
示例#3
0
        public void ApplyOnKeyUp(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
        {
            var now = Utility.GetMachineTime();

            // Exit conditions: exceeded the maximum delay OR user has delayed too long between key presses (and has probably noticed the delay).
            if (_CurrentDelay > _MaxDelay || now.Subtract(_LastDetectedKeyPress).CompareTo(_KeyPressDeltaToAbort) > 0)
            {
                _IsComplete = true;
                return;
            }

            // If this keypress corresponds to a typable character, queue a delay after it.
            var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted);

            if (c != '\0')
            {
                output.Delay(_CurrentDelay);

                // Increment the current delay for the next keypress.
                _CurrentDelay += _DelayIncrement;
            }

            // Keep the time of the last key press for next call.
            _LastDetectedKeyPress = now;
        }
示例#4
0
 public void ApplyOnKeyDown(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
 {
     // Record the initial keypress time after publish.
     if (_LastDetectedKeyPress < TimeSpan.Zero)
     {
         _LastDetectedKeyPress = Utility.GetMachineTime();
     }
 }
示例#5
0
        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: queue a backspace to delete it.
            var c = KeyboardTables.KeyToChar(thisKeyPress, isShifted);

            if (c != '\0' && !altPressed && !ctlPressed && !logoPressed)
            {
                output.KeyPress(KeyboardKey.BackSpace);
                _IsComplete = true;
            }
        }
示例#6
0
        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;
            }
        }
示例#7
0
        public void TestPush()
        {
            var buffer = new DelayBuffer <int>(2);

            Assert.AreEqual(0, buffer[-1]);
            Assert.AreEqual(0, buffer[0]);

            buffer.Push(42);
            Assert.AreEqual(0, buffer[-1]);
            Assert.AreEqual(42, buffer[0]);

            buffer.Push(33);
            Assert.AreEqual(42, buffer[-1]);
            Assert.AreEqual(33, buffer[0]);

            buffer.Push(800);
            Assert.AreEqual(33, buffer[-1]);
            Assert.AreEqual(800, buffer[0]);
        }
示例#8
0
 public void UpdateSkill()
 {
     while (delayBufferList.Count > 0)
     {
         DelayBuffer element = delayBufferList[0];
         element.time -= Time.deltaTime;
         if (element.time <= 0)
         {
             SkillInfo skill = skillDic[element.skillId];
             ActivateBuffer(skill.dataPO);
             delayBufferList.RemoveAt(0);
         }
         else
         {
             delayBufferList[0] = element;
             break;
         }
     }
 }
        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;
            }
        }
 public void ApplyOnKeyDown(DelayBuffer output, KeyboardKey thisKeyPress, bool isShifted, bool altPressed, bool ctlPressed, bool logoPressed)
 {
     // No-op.
 }