Esempio n. 1
0
        public void Test1()
        {
            string text = string.Empty;

            var interceptor = new FakeKeyboardInterceptor();
            var converter = new NaturalTextConverter(new ProcessorsBuilder());
            var viewModel = new KeyLogModel(interceptor);
            viewModel.PropertyChanged += (o,e)=> text = (string)converter.Convert(viewModel.Buffer, null, null, null);

            interceptor.Press("Right");
            interceptor.Press("Left");
            interceptor.Press("Up");
            interceptor.Press("Down");

            interceptor.Press("Escape");
            interceptor.Press("Enter");
            interceptor.Press("PageUp");
            interceptor.Press("PageDown");
            interceptor.Press("Tab");
            interceptor.Press("Insert");
            interceptor.Press("Delete");
            interceptor.Press("LControlKey");
            interceptor.Press("LControlKey");

            Assert.AreEqual("⇨⇦⇧⇩⎋↵PgUpPgDnTabInsDel", text);
        }
        public void SymbolicKeysTranslatorConstructorTest()
        {
            var builder = new FakeProcessorsBuilder(new[] { new SymbolicKeysTranslator() });
            var converter = new NaturalTextConverter(builder);
            var events = new [] { KeyboardEvent.FromKeys(Keys.Enter), KeyboardEvent.FromKeys(Keys.Escape) };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("\u21b5\u238b", actual);
        }
        public void IgnoreCtrlShiptOnly()
        {
            var converter = new NaturalTextConverter(new FakeProcessorsBuilder(new[] { new ShortcutProcessor() }));
            var events = new[] {
                KeyboardEvent.FromKeys(Keys.Control | Keys.LShiftKey ),
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("", actual);
        }
        public void IgnoreCtrlandAlt2()
        {
            var converter = new NaturalTextConverter(new FakeProcessorsBuilder(new IEventProcessor[] { new ShortcutProcessor(), new RawProcessor() }));
            var events = new[] {
                KeyboardEvent.FromKeys(Keys.Control),
                KeyboardEvent.FromKeys(Keys.Alt),
                KeyboardEvent.FromKeys(Keys.Control | Keys.I)
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("CtrlAltCtrl+I", actual);
        }
        public void AllInOne()
        {
            var converter = new NaturalTextConverter(new ProcessorsBuilder());
            var events = new[] {
                KeyboardEvent.FromChar('1'), KeyboardEvent.FromChar('a'),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),
                KeyboardEvent.FromChar('p'), KeyboardEvent.FromChar('a'), KeyboardEvent.FromChar('s'), KeyboardEvent.FromChar('s'), KeyboardEvent.FromKeys(Keys.Enter),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),
                KeyboardEvent.FromChar('3'), KeyboardEvent.FromChar('7'), KeyboardEvent.FromKeys(Keys.Escape), KeyboardEvent.FromKeys(Keys.Tab)
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("1aCtrl+KCtrl+L*****Ctrl+KCtrl+L37\u238bTab", actual);
        }
        public void HidePasswordTest()
        {
            var builder = new FakeProcessorsBuilder(new[] { new PasswordProcessor() });
            var converter = new NaturalTextConverter(builder);
            var events = new[] {
                KeyboardEvent.FromChar('1'), KeyboardEvent.FromChar('a'),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),  // password mode shortcut (E)
                KeyboardEvent.FromChar('p'), KeyboardEvent.FromChar('a'), KeyboardEvent.FromChar('s'), KeyboardEvent.FromChar('s'),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),  // password mode shortcut (D)
                KeyboardEvent.FromChar('3'), KeyboardEvent.FromChar('7'),
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("****", actual);
        }
        public void ShowAllevenPasswordTest()
        {
            var builder = new FakeProcessorsBuilder(new[] { new CharKeyProcessor() });
            var converter = new NaturalTextConverter(builder);
            var events = new[] {
                KeyboardEvent.FromChar('1'), KeyboardEvent.FromChar('a'),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),
                KeyboardEvent.FromChar('p'), KeyboardEvent.FromChar('a'), KeyboardEvent.FromChar('s'), KeyboardEvent.FromChar('s'),
                KeyboardEvent.FromKeys(Keys.Control | Keys.K), KeyboardEvent.FromKeys(Keys.Control | Keys.L),
                KeyboardEvent.FromChar('3'), KeyboardEvent.FromChar('7'),
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("1apass37", actual);
        }
        public void IgnoreLMenu()
        {
            var converter = new NaturalTextConverter(new FakeProcessorsBuilder(new IEventProcessor[] { new ShortcutProcessor(), new RawProcessor() }));
            var events = new[] {
                KeyboardEvent.FromKeys(Keys.LMenu),
                KeyboardEvent.FromKeys(Keys.LMenu),
                KeyboardEvent.FromKeys(Keys.LMenu),
                KeyboardEvent.FromKeys(Keys.LMenu)
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("", actual);
        }
        public void IgnoreDownLeftRightUp()
        {
            var converter = new NaturalTextConverter(new FakeProcessorsBuilder(new[] { new ShortcutProcessor() }));
            var events = new[] {
                KeyboardEvent.FromKeys(Keys.Down),
                KeyboardEvent.FromKeys(Keys.Up),
                KeyboardEvent.FromKeys(Keys.Left),
                KeyboardEvent.FromKeys(Keys.Right),
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("", actual);
        }
        public void RepeatCtrl()
        {
            var converter = new NaturalTextConverter(new FakeProcessorsBuilder(new[] { new ShortcutProcessor() }));
            var events = new[] {
                KeyboardEvent.FromKeys(Keys.LControlKey),
                KeyboardEvent.FromKeys(Keys.LControlKey),
                KeyboardEvent.FromKeys(Keys.LControlKey),
                KeyboardEvent.FromKeys(Keys.Control),
                KeyboardEvent.FromKeys(Keys.LControlKey)
            };

            var actual = converter.Convert(events, null, null, null);

            Assert.AreEqual("", actual);
        }