/// <summary>
        ///     Everytime a WM_ENTERSIZEMOVE is received,
        ///     records the information of the window before the change
        ///     and wait for the WM_EXITSIZEMOVE.
        ///     Everytime a WM_EXITSIZEMOVE is received,
        ///     records the information of the window after the change
        ///     and see if the windows has been moved
        ///     (by if (Utility.IsRectSizeEqual(windowRecBeforeChange,windowRecAfterChange)))
        ///     If so, records the relevant information into a WindowMovementEvent.
        /// </summary>
        /// <param name="msg">the hook message</param>
        private void WindowHookCallback(GlobalHook.HookMessage msg)
        {
            if (msg.Type == (uint)GlobalHook.MessageType.WM_ENTERSIZEMOVE)
            {
                windowUnderChangeHwnd = (int)msg.Hwnd;
                windowRecBeforeChange = new Rectangle();
                nativeWindowManagement?.GetWindowRect(windowUnderChangeHwnd, ref windowRecBeforeChange);
            }

            if (msg.Type == (uint)GlobalHook.MessageType.WM_EXITSIZEMOVE)
            {
                windowRecAfterChange = new Rectangle();
                nativeWindowManagement?.GetWindowRect(windowUnderChangeHwnd, ref windowRecAfterChange);
                if (nativeWindowManagement?.IsRectSizeEqual(windowRecBeforeChange, windowRecAfterChange) ?? false)
                {
                    var oldLocation = nativeWindowManagement.GetPoint(windowRecBeforeChange.X, windowRecBeforeChange.Y);
                    var newLocation = nativeWindowManagement.GetPoint(windowRecAfterChange.X, windowRecAfterChange.Y);
                    var @event      = new WindowMovementEvent
                    {
                        IssuingModule = WindowManagementModule.Identifier,
                        OldLocation   = oldLocation,
                        NewLocation   = newLocation,
                        Title         = nativeWindowManagement.GetWindowTitleFromHwnd(msg.Hwnd),
                        ProcessName   = nativeWindowManagement.GetProcessNameFromHwnd(msg.Hwnd)
                    };
                    Enqueue(@event);
                }
            }
        }
Exemple #2
0
        private void GlobalHookCallBack(GlobalHook.HookMessage message)
        {
            string text;

            try
            {
                if (nativeClipboard == null)
                {
                    return;
                }

                text = nativeClipboard.GetClipboardText();
            }
            catch (Exception)
            {
                return;
            }

            //create the corresponding new Event
            var clipboardCutEvent = new ClipboardCutEvent
            {
                ClipboardText = text, IssuingModule = ClipboardModule.Identifier
            };

            //enqueue the new event.
            Enqueue(clipboardCutEvent);
        }
        private void MouseHookCallback(GlobalHook.HookMessage hookMessage)
        {
            //One wheel click is defined as WHEEL_DELTA, which is 120.
            //The scroll amount is the high order word of the wParam
            var highOrderWord = (hookMessage.wParam.ToInt64() >> 16) & 0xffff;
            var scrollAmount  = (short)highOrderWord;
            var mousePosition = new Point {
                X = hookMessage.Data[0], Y = hookMessage.Data[1]
            };
            var hwnd   = hookMessage.Hwnd.ToString();
            var @event = new MouseScrollEvent {
                ScrollAmount = scrollAmount, MousePosition = mousePosition, HWnd = hwnd, IssuingModule = MouseModule.Identifier
            };

            Enqueue(@event);
        }
        private void KeyboardHookCallback(GlobalHook.HookMessage hookMessage)
        {
            var virtualKeyCode = hookMessage.wParam;
            var pressedKey     = nativeKeyboard?.KeyFromVirtualKey((int)virtualKeyCode) ?? Key.None;
            var modifierKeys   = GetModifierKeys();
            var key            = nativeKeyboard?.ToUnicode((uint)virtualKeyCode) ?? '\u0000';

            var keyboardEvent = new KeyboardInteractEvent
            {
                MappedCharacter_Unicode                        = key,
                PressedKey_System_Windows_Input_Key            = pressedKey,
                ModifierKeys_System_Windows_Input_ModifierKeys = modifierKeys,
                IssuingModule    = KeyboardModule.Identifier,
                PressedKeyName   = pressedKey.ToString(),
                ModifierKeysName = modifierKeys.ToString()
            };

            Enqueue(keyboardEvent);
        }
        private void MouseHookCallback(GlobalHook.HookMessage hookMessage)
        {
            var messageType = (GlobalHook.MessageType)hookMessage.Type;
            var mouseAction = GetMouseAction(messageType);

            if (mouseAction == MouseAction.None)
            {
                return;
            }

            var mousePosition = new Point {
                X = hookMessage.Data[0], Y = hookMessage.Data[1]
            };
            var hwnd   = hookMessage.Hwnd.ToString();
            var @event = new MouseClickEvent {
                MouseAction = mouseAction, MousePosition = mousePosition, HWnd = hwnd, IssuingModule = MouseModule.Identifier
            };

            Enqueue(@event);
        }
        /// <summary>
        ///     Everytime a WM_ACTIVATE is received, check if this message contains the information
        ///     of a window being activated (by (int)msg.wParam == WA_ACTIVE) and if the Message
        ///     contains new information (by lastHwnd != hwnd). If the both requirements are met,
        ///     record the information of the activated window in a WindowFocusEvent.
        /// </summary>
        /// <param name="msg">the hook message</param>
        private void WindowHookCallback(GlobalHook.HookMessage msg)
        {
            if ((int)msg.wParam == WA_ACTIVE && nativeWindowManagement != null)
            {
                var hwnd = nativeWindowManagement.GetForegroundWindow();
                if (lastHwnd != hwnd)
                {
                    var processName = nativeWindowManagement.GetProcessNameFromHwnd(hwnd);
                    var windowTitle = nativeWindowManagement.GetWindowTitleFromHwnd(hwnd);
                    var @event      = new WindowFocusEvent
                    {
                        IssuingModule = WindowManagementModule.Identifier,
                        ProcessName   = processName,
                        Title         = windowTitle
                    };
                    Enqueue(@event);
                }

                lastHwnd = hwnd;
            }
        }
        /// <summary>
        ///     Everytime a WM_ENTERSIZEMOVE is received,
        ///     records the information of the window before the change
        ///     and wait for the WM_EXITSIZEMOVE.
        ///     Everytime a WM_EXITSIZEMOVE is received,
        ///     records the information of the window after the change
        ///     and see if the window has been resized.
        ///     (by if !(Utility.IsRectSizeEqual(windowRecBeforeChange,windowRecAfterChange)))
        ///     If so, records the relevant information into a WindowResizingEvent.
        /// </summary>
        /// <param name="msg">the hook message</param>
        private void WindowHookCallback(GlobalHook.HookMessage msg)
        {
            if (msg.Type == (uint)GlobalHook.MessageType.WM_ENTERSIZEMOVE)
            {
                windowUnderChangeHwnd = (int)msg.Hwnd;
                windowRecBeforeChange = new Rectangle();
                nativeWindowManagement?.GetWindowRect(windowUnderChangeHwnd, ref windowRecBeforeChange);
            }

            if (msg.Type == (uint)GlobalHook.MessageType.WM_EXITSIZEMOVE)
            {
                windowRecAfterChange = new Rectangle();
                nativeWindowManagement?.GetWindowRect(windowUnderChangeHwnd, ref windowRecAfterChange);
                if (nativeWindowManagement != null && !nativeWindowManagement.IsRectSizeEqual(windowRecBeforeChange, windowRecAfterChange))
                {
                    var oldSize = new Size
                    {
                        Width  = nativeWindowManagement.GetWindowWidth(windowRecBeforeChange),
                        Height = nativeWindowManagement.GetWindowHeight(windowRecBeforeChange)
                    };
                    var newSize = new Size
                    {
                        Width  = nativeWindowManagement.GetWindowWidth(windowRecAfterChange),
                        Height = nativeWindowManagement.GetWindowHeight(windowRecAfterChange)
                    };
                    var @event = new WindowResizingEvent
                    {
                        IssuingModule = WindowManagementModule.Identifier,
                        OldSize       = oldSize,
                        NewSize       = newSize,
                        Title         = nativeWindowManagement.GetWindowTitleFromHwnd(msg.Hwnd),
                        ProcessName   = nativeWindowManagement.GetProcessNameFromHwnd(msg.Hwnd)
                    };
                    Enqueue(@event);
                }
            }
        }
Exemple #8
0
 /* WHEN */
 static void Listener(GlobalHook.HookMessage message)
 {
     /* THEN */
     Assert.Fail("The listener should not get called!");
 }