public void GetMetadataRandomStringsTest()
        {
            WindowsKey validWindowsKey = GetWindowsKey();

            // Check we ignore extraneous new lines and non-windows-key strings.
            GetMetadataTest(
                input: string.Format("{{}}\n\n\nhello\n{0}\n!@#$%^&*()\n\n\n{0}", validWindowsKey.ToString()),
                expected: new List <WindowsKey> {
                validWindowsKey, validWindowsKey
            });

            // Additional fields in the key should be ignored.
            string windowsKeyJson =
                "{\"userName\":\"test\",\"exponent\":\"test\",\"modulus\":\"test\",\"extra\":\"test\"}";

            validWindowsKey = GetWindowsKey(userName: "******", exponent: "test", modulus: "test", email: string.Empty);
            GetMetadataTest(
                input: windowsKeyJson,
                expected: new List <WindowsKey> {
                validWindowsKey
            });

            // Invalid argument types should not be parsed as a windows key.
            windowsKeyJson = "{" +
                             "\"userName\":\"test\"," +
                             "\"exponent\":\"test\"," +
                             "\"modulus\":\"test\"," +
                             "\"extra\":\"test\"," +
                             "\"info\":{{\"json\":\"input\"}}" +
                             "}";
            validWindowsKey = GetWindowsKey(userName: "******", exponent: "test", modulus: "test", email: string.Empty);
            GetMetadataTest(
                input: windowsKeyJson,
                expected: new List <WindowsKey> {
                validWindowsKey
            });
        }
Exemplo n.º 2
0
        private void AddSpecialKey(SpecialKey specialKey)
        {
            KeyControl key;

            switch (specialKey.KeyType)
            {
            case SpecialKeyType.Shift:
                key = new ShiftKey();
                break;

            case SpecialKeyType.Win:
                key = new WindowsKey();
                break;

            case SpecialKeyType.Tab:
                key = new TabKey();
                break;

            case SpecialKeyType.Captial:
                key = new CapsKey();
                break;

            case SpecialKeyType.Return:
                key = new EnterKey();
                break;

            case SpecialKeyType.Back:
                key = new BackKey();
                break;

            default:
                return;
            }
            key.IsPressed = specialKey.IsDown;
            _currentKeyItem.InlineCollection.Add(key);
        }
Exemplo n.º 3
0
 public static IEnumerable <SpectrumKey> SpectrumKeysForWindowsKey(WindowsKey key)
 {
     return(_keyMap[(int)key]);
 }
        private void UpdateView(List <KeyLogEntry> keyLogEntries)
        {
            var newContent = new List <KeyItem>();

            if (keyLogEntries == null)
            {
                KeyLogContent = new ObservableCollection <KeyItem>();
                OnPropertyChanged(nameof(KeyLogContent));
                return;
            }

            var currentKeyItem  = new KeyItem();
            var placeholderText = Application.Current.Resources["NoKeyInputs"];

            foreach (var keyLogEntry in keyLogEntries)
            {
                var normalTextEntry = keyLogEntry as NormalText;
                if (normalTextEntry != null)
                {
                    if (!string.IsNullOrEmpty(normalTextEntry.Text))
                    {
                        currentKeyItem.InlineCollection.Add(normalTextEntry.Text);
                    }
                    continue;
                }

                var specialKey = keyLogEntry as SpecialKey;
                if (specialKey != null)
                {
                    KeyControl key;
                    switch (specialKey.KeyType)
                    {
                    case SpecialKeyType.Shift:
                        key = new ShiftKey();
                        break;

                    case SpecialKeyType.Win:
                        key = new WindowsKey();
                        break;

                    case SpecialKeyType.Tab:
                        key = new TabKey();
                        break;

                    case SpecialKeyType.Captial:
                        key = new CapsKey();
                        break;

                    case SpecialKeyType.Return:
                        key = new EnterKey();
                        break;

                    case SpecialKeyType.Back:
                        key = new BackKey();
                        break;

                    default:
                        continue;
                    }

                    if (HideReleaseKeyState && !specialKey.IsDown)
                    {
                        continue;
                    }

                    key.IsPressed = specialKey.IsDown;
                    currentKeyItem.InlineCollection.Add(key);
                    continue;
                }

                var standardKey = keyLogEntry as StandardKey;
                if (standardKey != null)
                {
                    if (HideReleaseKeyState && !standardKey.IsDown)
                    {
                        continue;
                    }

                    string text;
                    switch (standardKey.Key)
                    {
                    case Keys.Alt:
                        text = "Alt";
                        break;

                    case Keys.RMenu:
                        text = "Alt Gr";
                        break;

                    case Keys.Delete:
                        text = "Del";
                        break;

                    case Keys.Control:
                    case Keys.LControlKey:
                        text = "Ctrl";
                        break;

                    default:
                        text = standardKey.ToString();
                        break;
                    }
                    currentKeyItem.InlineCollection.Add(new ViewModels.KeyLog.StandardKey(text)
                    {
                        IsPressed = standardKey.IsDown
                    });
                    continue;
                }

                var windowChanged = keyLogEntry as WindowChanged;
                if (windowChanged != null)
                {
                    if (currentKeyItem.InlineCollection.Count == 0)
                    {
                        if (HideEmptyWindows)
                        {
                            newContent.Remove(currentKeyItem);
                        }
                        else
                        {
                            currentKeyItem.InlineCollection.Add(
                                new Italic(new Run("(" + placeholderText + ")")
                            {
                                Foreground = (Brush)Application.Current.Resources["BlackBrush"]
                            }));
                        }
                    }

                    currentKeyItem = new KeyItem
                    {
                        ApplicationName = windowChanged.WindowTitle,
                        Timestamp       = windowChanged.Timestamp
                    };
                    newContent.Add(currentKeyItem);
                }
            }

            KeyLogContent = new ObservableCollection <KeyItem>(newContent);
            OnPropertyChanged(nameof(KeyLogContent));
        }