Пример #1
0
        public void KeyWasReleased(char charReleased, long timeInTicks)
        {
            charsReleased.Add(charReleased);

            timeSinceLastAction = timeInTicks;

            KeyPressRelease keyReleased = KeysPressedAndReleased.LastOrDefault(x => x.Character == charReleased);

            if (keyReleased != null)
            {
                keyReleased.TimeReleasedInTicks = timeInTicks;
            }



            KeysData keysData = KeysDataWhereFirstCharIs(charReleased);

            if (keysData != null)
            {
                RecordOnReleaseData(charReleased, timeInTicks, keysData);
            }

            keysCurrentlyHeld.Remove(charReleased);
            timeOfPreviousRelease   = timeInTicks;
            previousReleaseKeysData = keysData;
        }
Пример #2
0
        private void RecordOnReleaseData(char charReleased, long timeInTicks, KeysData keysData)
        {
            keysData.WaitingForEvents.Remove(KeysData.WaitingForEvent.EFirstKeyRelease);

            keysData.HoldTime = TimeSpan.FromTicks(timeInTicks - keysCurrentlyHeld[charReleased]);

            if (NextKeyAlreadyPressed(keysData))
            {
                KeyPressRelease keyReleased = KeysPressedAndReleased.FirstOrDefault(x => x.Character == keysData.SecondChar);
                if (keyReleased != null)
                {
                    keysData.FlightTime = TimeSpan.FromTicks(keyReleased.TimePressedInTicks - timeInTicks);
                }
            }

            KeysData previousKeyData = KeysDataWhereSecondCharIs(charReleased);

            if (previousKeyData != null)
            {
                previousKeyData.WaitingForEvents.Remove(KeysData.WaitingForEvent.ESecondKeyRelease);
            }

            if (previousReleaseKeysData != null)
            {
                if (KeysDataWhereSecondCharIs(charReleased) == null)
                {
                    KeyPressRelease secondKeyReleasedFirst = KeysPressedAndReleased[KeysPressedAndReleased.FindIndex(x => x.Character == keysData.FirstChar) + 1];



                    keysData.Digraph2 = TimeSpan.FromTicks(secondKeyReleasedFirst.TimeReleasedInTicks - timeInTicks);
                    keysData.Digraph3 = GetDigraph3(keysData);

                    RemoveUnnecesarryKeys(charReleased);
                }
                else // This happens when the second key of the key combination is released first
                {
                    previousKeyData = KeysDataWhereSecondCharIs(charReleased);

                    previousKeyData.Digraph2 = GetDigraph2(timeInTicks, previousKeyData);
                    previousKeyData.Digraph3 = GetDigraph3(previousKeyData);

                    previousKeyData.WaitingForEvents.Remove(KeysData.WaitingForEvent.ESecondKeyRelease);


                    KeyPressRelease secondKeyReleasedFirst = KeysPressedAndReleased.FirstOrDefault(x => x.Character == keysData.SecondChar);

                    if (secondKeyReleasedFirst != null)
                    {
                        keysData.Digraph2 = TimeSpan.FromTicks(secondKeyReleasedFirst.TimeReleasedInTicks - timeInTicks);
                        keysData.Digraph3 = GetDigraph3(keysData);
                    }

                    RemoveUnnecesarryKeys(charReleased);
                }
            }
        }
Пример #3
0
        private TimeSpan GetDigraph2(long timeInTicks, KeysData keysData)
        {
            KeyPressRelease keyReleased = KeysPressedAndReleased.FirstOrDefault(x => x.Character == keysData.FirstChar);

            if (keyReleased != null)
            {
                return(TimeSpan.FromTicks(timeInTicks - keyReleased.TimeReleasedInTicks));
            }
            return(new TimeSpan(0));
        }