Exemplo n.º 1
0
        private IntPtr HookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                int bScan  = Marshal.ReadInt32(lParam, 4);
                events.Add(new KeyValuePair <EventArgs, EventDetails>(new KeyData(vkCode, bScan, 0), new EventDetails(EventType.KEYBOARDEVENT, DelayCounter.Delay)));
                DelayCounter.ResetDelay();
            }
            else if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                int bScan  = Marshal.ReadInt32(lParam, 4);
                events.Add(new KeyValuePair <EventArgs, EventDetails>(new KeyData(vkCode, bScan, KEYEVENTF_KEYUP), new EventDetails(EventType.KEYBOARDEVENT, DelayCounter.Delay)));
                DelayCounter.ResetDelay();
            }

            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
        private IntPtr MouseHookProcedure(int nCode, IntPtr wParam, IntPtr lParam)
        {
            MouseHookStruct mouseStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));

            if (nCode >= 0)
            {
                switch ((MouseMessages)wParam)
                {
                case MouseMessages.WM_LBUTTONDOWN:
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, 0, (MouseEventFlags.MOUSEEVENTF_LEFTDOWN), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;

                case MouseMessages.WM_LBUTTONUP:
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, 0, (MouseEventFlags.MOUSEEVENTF_LEFTUP), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;

                case MouseMessages.WM_MOUSEMOVE:
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, 0, (MouseEventFlags.MOUSEEVENTF_ABSOLUTE | MouseEventFlags.MOUSEEVENTF_MOVE), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;

                case MouseMessages.WM_MOUSEWHEEL:
                    int mouseData = mouseStruct.mouseData;
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, mouseData, (MouseEventFlags.MOUSEEVENTF_WHEEL), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;

                case MouseMessages.WM_RBUTTONDOWN:
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, 0, (MouseEventFlags.MOUSEEVENTF_RIGHTDOWN), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;

                case MouseMessages.WM_RBUTTONUP:
                    events.Add(new KeyValuePair <EventArgs, EventDetails>(new MouseData(mouseStruct.point.x, mouseStruct.point.y, 0, (MouseEventFlags.MOUSEEVENTF_RIGHTUP), (uint)mouseStruct.time, mouseStruct.dwExtraInfo), new EventDetails(EventType.MOUSEEVENT, DelayCounter.Delay)));
                    DelayCounter.ResetDelay();
                    break;
                }
            }
            return(CallNextHookEx(hookID, nCode, wParam, lParam));
        }