private void buttonInstall_Click(object sender, System.EventArgs e)
        {
            // EXAMPLE CODE SECTION

            AddText("Adding mouse hook.");
            mouseHook.InstallHook();

            AddText("Adding keyboard hook.");
            keyboardHook.InstallHook();

            UpdateEnabledStates();
        }
        public void EventTest(TestMethodRecord tmr)
        {
            KeyboardHookEventArgs[] keyArgs = GenerateRandomKeyData();

            KeyboardHookTestImpl hookImpl = new KeyboardHookTestImpl();

            using (IKeyboardHookExt keyboard = HookFactory.CreateKeyboardHookExt(hookImpl))
            {
                keyboard.InstallHook();

                keyboard.KeyDown += new KeyboardEventHandlerExt(EventTest_KeyDown);

                //
                // Trigger a bunch of keyboard events. The event handler will
                // capture the output and we will then compare it here.
                //
                foreach (KeyboardHookEventArgs keyArg in keyArgs)
                {
                    hookImpl.TriggerKeyAction(KeyboardEvents.KeyDown, keyArg);
                }
            }

            tmr.RunTest(keyArgs.Length == eventTest_ArgsList.Count, "The proper number of events were caught.");

            bool same = true;

            for (int i = 0; i < keyArgs.Length; i++)
            {
                KeyboardHookEventArgs kea1 = keyArgs[i];
                KeyboardHookEventArgs kea2 = (KeyboardHookEventArgs)eventTest_ArgsList[i];

                if (!CompareKeyArgs(kea1, kea2))
                {
                    tmr.WriteLine("Failed event results comparison at index " + i);
                    same = false;
                    break;
                }
            }

            tmr.RunTest(same, "The event callback captured all the events successfully.");
        }
        public void SortedEventTest(TestMethodRecord tmr)
        {
            KeyboardHookTestImpl hookImpl = new KeyboardHookTestImpl();
            IKeyboardHookExt     keyboard = HookFactory.CreateKeyboardHookExt(hookImpl);

            keyboard.InstallHook();

            keyboard.KeyDown       += new KeyboardEventHandlerExt(SortedEventTest_KeyDown);
            keyboard.KeyUp         += new KeyboardEventHandlerExt(SortedEventTest_KeyUp);
            keyboard.SystemKeyUp   += new KeyboardEventHandlerExt(SortedEventTest_SystemKeyUp);
            keyboard.SystemKeyDown += new KeyboardEventHandlerExt(SortedEventTest_SystemKeyDownKeyUp);

            KeyboardHookEventArgs[] keyArgs = GenerateRandomKeyData();

            KeyboardHookEventArgs kea1 = keyArgs[0];
            KeyboardHookEventArgs kea2 = keyArgs[1];
            KeyboardHookEventArgs kea3 = keyArgs[2];
            KeyboardHookEventArgs kea4 = keyArgs[3];

            hookImpl.TriggerKeyAction(KeyboardEvents.KeyDown, kea1);
            hookImpl.TriggerKeyAction(KeyboardEvents.KeyUp, kea2);
            hookImpl.TriggerKeyAction(KeyboardEvents.SystemKeyDown, kea3);
            hookImpl.TriggerKeyAction(KeyboardEvents.SystemKeyUp, kea4);

            tmr.RunTest(sortedEventTest_ArgsListDown.Count == 1, "One KeyDown event trigged.");
            tmr.RunTest(sortedEventTest_ArgsListUp.Count == 1, "One KeyUp event trigged.");
            tmr.RunTest(sortedEventTest_ArgsListSysDown.Count == 1, "One SystemKeyDown event trigged.");
            tmr.RunTest(sortedEventTest_ArgsListSysUp.Count == 1, "One SystemKeyUp event trigged.");

            KeyboardHookEventArgs keaB1 = (KeyboardHookEventArgs)sortedEventTest_ArgsListDown[0];
            KeyboardHookEventArgs keaB2 = (KeyboardHookEventArgs)sortedEventTest_ArgsListUp[0];
            KeyboardHookEventArgs keaB3 = (KeyboardHookEventArgs)sortedEventTest_ArgsListSysDown[0];
            KeyboardHookEventArgs keaB4 = (KeyboardHookEventArgs)sortedEventTest_ArgsListSysUp[0];

            tmr.RunTest(CompareKeyArgs(kea1, keaB1), "Correct KeyDown event caught.");
            tmr.RunTest(CompareKeyArgs(kea2, keaB2), "Correct KeyUp event caught.");
            tmr.RunTest(CompareKeyArgs(kea3, keaB3), "Correct SysKeyDown event caught.");
            tmr.RunTest(CompareKeyArgs(kea4, keaB4), "Correct SysKeyUp event caught.");
        }