public void KeyboardHookFilterPositive()
        {
            int  pressedkey = -1;
            bool fired      = false;

            KeyboardHook hook = new KeyboardHook();

            hook.KeyDetected += new KeyHookEventHandler(
                delegate(OpenNETCF.Win32.WM keyMessage, KeyData keyData)
            {
                pressedkey = keyData.KeyCode;
                fired      = true;
            });

            Form f = new Form();

            f.ClientSize = new System.Drawing.Size(240, 268);
            TextBox t = new TextBox();

            t.Multiline = true;
            f.Controls.Add(t);
            f.Show();
            Application2.DoEvents();
            t.Focus();
            Application2.DoEvents();

            SendKeys.Send("a");
            Application2.DoEvents();

            Assert.IsFalse(fired, "hook fired when disabled");

            hook.Enabled = true;
            SendKeys.Send("h");
            Application2.DoEvents();

            Assert.IsTrue(fired, "hook did not fire when enabled");
            Assert.AreEqual((int)Keys.H, pressedkey);
            Application2.DoEvents();
            Assert.AreEqual("ah", t.Text);

            hook.PassOnKeys = false;
            fired           = false;
            SendKeys.Send("a");
            Application2.DoEvents();

            // hook should fire, get the key data, but the textbox should *not* get the character
            Assert.IsTrue(fired, "hook did not fire");
            Assert.AreEqual((int)Keys.A, pressedkey);
            Application2.DoEvents();
            Assert.AreEqual("ah", t.Text);

            hook.Dispose();
            f.Close();
            f.Dispose();
        }
Beispiel #2
0
        public void AddMessageFilterTest()
        {
            AutoResetEvent filterEvent = new AutoResetEvent(false);
            TestFilter     filter      = new TestFilter(filterEvent);

            Application2.AddMessageFilter(filter);

            Form f = new Form();

            f.Visible = true;
            Application2.DoEvents();

            Assert.IsTrue(filterEvent.WaitOne(1000, false), "Filter PreFilterMessage was not called");

            filterEvent.Close();
            f.Dispose();
            Application2.Exit();
        }
Beispiel #3
0
        public void SendKeysTestPositive()
        {
            Form f = new Form();

            f.ClientSize = new System.Drawing.Size(240, 268);
            TextBox t = new TextBox();

            t.Multiline = true;
            f.Controls.Add(t);
            f.Show();
            Application2.DoEvents();
            t.Focus();
            Application2.DoEvents();
            SendKeys.Send("hello");

            Application2.DoEvents();
            Application2.DoEvents();

            Assert.AreEqual("hello", t.Text);

            f.Close();
            f.Dispose();
        }