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));
        }
Exemple #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (mouseHandle != IntPtr.Zero)
                {
                    WindowsHookHelper.UnhookWindowsHookEx(mouseHandle);
                }

                disposed = true;
            }
        }
        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));
        }
Exemple #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));
        }
Exemple #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));
        }
 public KeyboardInput(IntPtr id)
 {
     keyBoardDelegate = this.KeyboardHookDelegate;
     keyBoardHandle   = WindowsHookHelper.SetWindowsHookEx(WH_KEYBOARD_LL, keyBoardDelegate, id, 0);
 }
Exemple #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));
        }
Exemple #9
0
 public MouseInput()
 {
     mouseDelegate = MouseHookDelegate;
     mouseHandle   = WindowsHookHelper.SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, IntPtr.Zero, 0);
 }
Exemple #10
0
 public KeyboardInput()
 {
     keyBoardDelegate = KeyboardHookDelegate;
     keyBoardHandle   = WindowsHookHelper.SetWindowsHookEx(
         WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 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);
        }