Esempio n. 1
0
 public void Dispose()
 {
     if (keyBoardHandle != IntPtr.Zero && WindowsHookHelper.UnhookWindowsHookEx(keyBoardHandle))
     {
         keyBoardHandle = IntPtr.Zero;
     }
 }
        private IntPtr KeyboardHookDelegate(
            Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            if (Code < 0)
            {
                return(WindowsHookHelper.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }

            if (KeyBoardKeyPressed != null)
            {
                KeyBoardKeyPressed(this, new EventArgs());
                if ((int)wParam == 256)//keydown
                {
                    int key = (int)Marshal.ReadInt32(lParam);
                    Console.WriteLine("key wPara: " + wParam);
                    Console.WriteLine("key code?: " + key);
                    if (key == 48)//0
                    {
                        //onOff
                    }
                }
            }
            // Console.WriteLine("key Code: " + Code);
            //Console.WriteLine("key wPara: " + wParam);
            //Console.WriteLine("key lPara: " + lParam);
            // Console.WriteLine("key hand: " + keyBoardHandle);


            return(WindowsHookHelper.CallNextHookEx(
                       keyBoardHandle, Code, wParam, lParam));
        }
Esempio n. 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (mouseHandle != IntPtr.Zero)
                {
                    WindowsHookHelper.UnhookWindowsHookEx(mouseHandle);
                }

                disposed = true;
            }
        }
Esempio n. 4
0
        private IntPtr KeyboardHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            if (Code >= 0)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                KeyBoardKeyPressed?.Invoke(this, new CharArgs()
                {
                    Key   = (VirtualKeys)vkCode,
                    Event = (KeyEvents)wParam
                });
            }

            return(WindowsHookHelper.CallNextHookEx(keyBoardHandle, Code, wParam, lParam));
        }
Esempio n. 5
0
        private IntPtr MouseHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            if (Code < 0)
            {
                return(WindowsHookHelper.CallNextHookEx(mouseHandle, Code, wParam, lParam));
            }

            if (MouseMoved != null)
            {
                MouseMoved(this, new EventArgs());
            }

            return(WindowsHookHelper.CallNextHookEx(mouseHandle, Code, wParam, lParam));
        }
Esempio n. 6
0
        private IntPtr KeyboardHookDelegate(
            Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            if (Code < 0)
            {
                return(WindowsHookHelper.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }

            if (KeyBoardKeyPressed != null)
            {
                KeyBoardKeyPressed(this, new EventArgs());
            }

            return(WindowsHookHelper.CallNextHookEx(
                       keyBoardHandle, Code, wParam, lParam));
        }
Esempio n. 7
0
 public KeyboardInput(IntPtr id)
 {
     keyBoardDelegate = this.KeyboardHookDelegate;
     keyBoardHandle   = WindowsHookHelper.SetWindowsHookEx(WH_KEYBOARD_LL, keyBoardDelegate, id, 0);
 }
Esempio n. 8
0
        private IntPtr MouseHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            //Console.WriteLine("mouse");
            if (Code < 0)
            {
                return(WindowsHookHelper.CallNextHookEx(mouseHandle, Code, wParam, lParam));
            }

            if (MouseMoved != null)
            {
                MouseMoved(this, new EventArgs());

                Console.WriteLine("wParam: " + wParam);

                if (wParam == (IntPtr)513)
                {
                    Console.WriteLine("left down");
                    //Location.X = Cursor.Position.X;
                    //Location.Y = Cursor.Position.Y;

                    leftDown = true;

                    if (isOn)
                    {
                        MyTaskAsync();
                    }


                    /*
                     * void mouse_event(
                     * DWORD     dwFlags,
                     * DWORD     dx,
                     * DWORD     dy,
                     * DWORD     dwData,
                     * ULONG_PTR dwExtraInfo
                     * );
                     */
                }
                if (wParam == (IntPtr)514)
                {
                    Console.WriteLine("left up");
                    leftDown = false;
                }
                if (wParam == (IntPtr)516)
                {
                    Console.WriteLine("right down");
                }
                if (wParam == (IntPtr)517)
                {
                    Console.WriteLine("right up");
                }
                if (wParam == (IntPtr)519)
                {
                    Console.WriteLine("m down");
                    if (isOn)
                    {
                        isOn = false;
                    }
                    else
                    {
                        isOn = true;
                    }
                }
                if (wParam == (IntPtr)520)
                {
                    Console.WriteLine("m up");
                }
            }
            return(WindowsHookHelper.CallNextHookEx(mouseHandle, Code, wParam, lParam));
        }
Esempio n. 9
0
 public MouseInput()
 {
     mouseDelegate = MouseHookDelegate;
     mouseHandle   = WindowsHookHelper.SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, IntPtr.Zero, 0);
 }
Esempio n. 10
0
 public KeyboardInput()
 {
     keyBoardDelegate = KeyboardHookDelegate;
     keyBoardHandle   = WindowsHookHelper.SetWindowsHookEx(
         WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 0);
 }
Esempio n. 11
0
        private void SendMessage(string cmd, Process p)
        {
            IntPtr child = WindowsHookHelper.GetWindow(p.MainWindowHandle, (IntPtr)WindowCmd.GW_CHILD);

            WindowsHookHelper.SendMessage(child, (IntPtr)WindowCmd.WM_SETTEXT, 0, cmd);
        }