public MainForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // Add any constructor code after InitializeComponent call
            //
            SetInitialMessage();

            // EXAMPLE CODE SECTION
            keyboardHook          = HookFactory.CreateKeyboardHookExt();
            keyboardHook.KeyDown += new KeyboardEventHandlerExt(keyboardHook_KeyDown);

            //
            // Note: Use IMouseHookExt for mouse move events.
            //
            mouseHook = HookFactory.CreateMouseHookLite();
            mouseHook.LeftButtonDown += new MouseEventHandlerExt(mouseHook_LeftButtonDown);
            mouseHook.LeftButtonUp   += new MouseEventHandlerExt(mouseHook_LeftButtonUp);
            mouseHook.MouseWheel     += new MouseEventHandlerExt(mouseHook_MouseWheel);

            UpdateEnabledStates();
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // EXAMPLE CODE SECTION
                using (mouseHook) { mouseHook = null; }
                using (keyboardHook) { keyboardHook = null; }

                using (components) { components = null; }
            }
            base.Dispose(disposing);
        }
Beispiel #3
0
        public void InstallHookTests(TestMethodRecord tmr)
        {
            using (IMouseHook mHook = HookFactory.CreateMouseHook())
            {
                TestInstallHook(tmr, mHook, "IMouseHook");
            }

            using (IMouseHookExt mHookExt = HookFactory.CreateMouseHookExt())
            {
                TestInstallHook(tmr, mHookExt, "IMouseHookExt");
            }

            using (IMouseHookLite mHookLite = HookFactory.CreateMouseHookLite())
            {
                TestInstallHook(tmr, mHookLite, "IMouseHookLite");
            }
        }
Beispiel #4
0
        public void CreateMouseHookTests(TestMethodRecord tmr)
        {
            using (IMouseHook mouseHook = HookFactory.CreateMouseHook())
            {
                tmr.RunTest(mouseHook != null, "IMouseHook created successfully with default options.");
            }

            using (IMouseHookExt mouseHookExt = HookFactory.CreateMouseHookExt())
            {
                tmr.RunTest(mouseHookExt != null, "IMouseHookExt created successfully with default options.");
            }

            using (IMouseHookLite mouseHookLite = HookFactory.CreateMouseHookLite())
            {
                tmr.RunTest(mouseHookLite != null, "IMouseHookLite created successfully with default options.");
            }
        }
Beispiel #5
0
        public void ReferenceCountingTest(TestMethodRecord tmr)
        {
            //
            // In this test we are observing how the various mouse hook
            // classes are interacting with their implementation classes. They
            // should add references in their constructor and release them when
            // disposed. The implementation should only be disposed when the ref
            // count is zero.
            //
            MouseHookTestImpl testImpl = new MouseHookTestImpl();

            tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0.");
            tmr.RunTest(testImpl.Disposed == false, "Not initially disposed.");

            using (IMouseHook hook1 = HookFactory.CreateMouseHook(testImpl))
            {
                tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1.");
                tmr.RunTest(testImpl.Disposed == false, "Not disposed.");

                using (IMouseHookExt hook2 = HookFactory.CreateMouseHookExt(testImpl))
                {
                    tmr.RunTest(testImpl.ReferenceCount == 2, "Now references count is 2.");
                    tmr.RunTest(testImpl.Disposed == false, "Not disposed.");

                    using (IMouseHookLite hook3 = HookFactory.CreateMouseHookLite(testImpl))
                    {
                        tmr.RunTest(testImpl.ReferenceCount == 3, "Now references count is 3.");
                        tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
                    }

                    tmr.RunTest(testImpl.ReferenceCount == 2, "Now references count is 2.");
                    tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
                }

                tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1.");
                tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
            }

            tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0.");
            tmr.RunTest(testImpl.Disposed == true, "Disposed.");
        }