public void StartCapture(INativeWindowManagement nativeWinManagement)
        {
            nativeWindowManagement = nativeWinManagement;
            GlobalHook.AddListener(WindowHookCallback, listenedMessageTypes);

            GlobalHook.IsActive = true;
        }
Exemple #2
0
        public void TestGlobalHook_AddListener()
        {
            /* PRECONDITIONS */
            Debug.Assert(hookNativeMethods != null);
            Debug.Assert(hookNativeMethods.Mock != null);

            /* GIVEN */
            const int numOfEvent    = 50;
            const int numOfNotEvent = 20;
            const GlobalHook.MessageType messageType = GlobalHook.MessageType.WM_USER;

            using var resetCounter = new CountdownEvent(numOfEvent);
            using var autoReset    = new AutoResetEvent(false);

            GlobalHook.CppGetMessageCallback callback = null;

            hookNativeMethods.AllowMessageTypeRegistry(messageType);
            hookNativeMethods.AllowLibraryLoad();
            hookNativeMethods.Mock
            .Setup(hook => hook.SetHook(It.IsAny <GlobalHook.CppGetMessageCallback>(), It.IsAny <bool>()))?
            .Callback((GlobalHook.CppGetMessageCallback cppCallback, bool isBlocking) =>
            {
                callback = cppCallback;
                autoReset.Set();
            });

            /* WHEN */
            GlobalHook.AddListener(message =>
            {
                Assert.AreEqual((uint)messageType, message.Type);
                resetCounter.Signal();
            }, messageType);

            GlobalHook.IsActive = true;

            Assert.IsTrue(autoReset.WaitOne(maxWaitTime));
            Assert.IsNotNull(callback);

            for (var index = 0; index < numOfEvent; index++)
            {
                callback(new GlobalHook.HookMessage()
                {
                    Type = (uint)messageType
                });
            }

            // We check if our listener still gets called on events we don't care about. If it will this
            // test will throw because the resetCounter will be set to a negative number.
            for (var index = 0; index < numOfNotEvent; index++)
            {
                callback(new GlobalHook.HookMessage()
                {
                    Type = (uint)GlobalHook.MessageType.WM_APP
                });
            }

            /* THEN */
            Assert.IsTrue(resetCounter.Wait(maxWaitTime));
        }
Exemple #3
0
        /// <summary>
        ///     Sets the hook for the clipboard cut event.
        /// </summary>
        public void StartCapture(IClipboardWindowMessageSink windowMessageSink, INativeClipboard nativeClip)
        {
            clipboardWindowMessageSink = windowMessageSink;
            nativeClipboard            = nativeClip;

            if (clipboardWindowMessageSink == null)
            {
                return;
            }

            clipboardWindowMessageSink.ClipboardUpdated += OnClipboardUpdate;

            GlobalHook.IsActive = true;
            GlobalHook.AddListener(GlobalHookCallBack, GlobalHook.MessageType.WM_CUT);
        }
Exemple #4
0
        public void TestGlobalHook_AddListener_UnsupportedMessageType()
        {
            /* PRECONDITIONS */
            Debug.Assert(hookNativeMethods != null);
            Debug.Assert(hookNativeMethods.Mock != null);

            /* GIVEN */
            const GlobalHook.MessageType messageType = GlobalHook.MessageType.WM_USER;

            hookNativeMethods.DisallowMessageTypeRegistry(messageType);

            /* WHEN */
            Assert.ThrowsException <NotSupportedException>(() => GlobalHook.AddListener(message => { }, messageType));

            /* THEN */
            hookNativeMethods.Mock.Verify(hook => hook.SetHook(It.IsAny <GlobalHook.CppGetMessageCallback>(), It.IsAny <bool>()), Times.Never);
        }
 public void StartCapture()
 {
     GlobalHook.AddListener(MouseHookCallback, listenedMessagesTypes);
     GlobalHook.IsActive = true;
 }
 public void StartCapture()
 {
     GlobalHook.AddListener(MouseHookCallback, GlobalHook.MessageType.WM_MOUSEWHEEL);
     GlobalHook.IsActive = true;
 }
 public void StartCapture(INativeKeyboard nativeK)
 {
     nativeKeyboard = nativeK;
     GlobalHook.AddListener(KeyboardHookCallback, listenedMessagesTypes);
     GlobalHook.IsActive = true;
 }
Exemple #8
0
 public void StartCapture(INativeClipboard nativeCl)
 {
     nativeClipboard     = nativeCl;
     GlobalHook.IsActive = true;
     GlobalHook.AddListener(GlobalHookCallBack, GlobalHook.MessageType.WM_PASTE);
 }