Ejemplo n.º 1
0
 public void Stop()
 {
     if (!this._isStarted)
     {
         return;
     }
     GlobalHook.UnhookWindowsHookEx(this._handleToHook);
     this._isStarted = false;
 }
Ejemplo n.º 2
0
 public void Start()
 {
     if (this._isStarted || this._hookType == 0)
     {
         return;
     }
     this._hookCallback = new GlobalHook.HookProc(this.HookCallbackProcedure);
     this._handleToHook = GlobalHook.SetWindowsHookEx(this._hookType, this._hookCallback, GlobalHook.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
     if (this._handleToHook == 0)
     {
         return;
     }
     this._isStarted = true;
 }
Ejemplo n.º 3
0
        protected override int HookCallbackProcedure(int nCode, int wParam, IntPtr lParam)
        {
            if (this.ScreenMsg)
            {
                return(-1);
            }
            bool flag1 = false;

            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            if (nCode > -1 && (this.KeyDown != null || this.KeyUp != null || this.KeyPress != null))
            {
                GlobalHook.KeyboardHookStruct keyboardHookStruct = (GlobalHook.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(GlobalHook.KeyboardHookStruct));
                bool         flag2 = ((int)GlobalHook.GetKeyState(162) & 128) != 0 || ((uint)GlobalHook.GetKeyState(3) & 128U) > 0U;
                bool         flag3 = ((int)GlobalHook.GetKeyState(160) & 128) != 0 || ((uint)GlobalHook.GetKeyState(161) & 128U) > 0U;
                bool         flag4 = ((int)GlobalHook.GetKeyState(164) & 128) != 0 || ((uint)GlobalHook.GetKeyState(165) & 128U) > 0U;
                bool         flag5 = (uint)GlobalHook.GetKeyState(20) > 0U;
                KeyEventArgs e     = new KeyEventArgs((Keys)(keyboardHookStruct.vkCode | (flag2 ? 131072 : 0) | (flag3 ? 65536 : 0) | (flag4 ? 262144 : 0)));
                switch (wParam)
                {
                case 256:
                case 260:
                    // ISSUE: reference to a compiler-generated field
                    if (this.KeyDown != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.KeyDown((object)this, e);
                        flag1 = flag1 || e.Handled;
                        break;
                    }
                    break;

                case 257:
                case 261:
                    // ISSUE: reference to a compiler-generated field
                    if (this.KeyUp != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.KeyUp((object)this, e);
                        flag1 = flag1 || e.Handled;
                        break;
                    }
                    break;
                }
                // ISSUE: reference to a compiler-generated field
                if (wParam == 256 && !flag1 && (!e.SuppressKeyPress && this.KeyPress != null))
                {
                    byte[] numArray    = new byte[256];
                    byte[] lpwTransKey = new byte[2];
                    GlobalHook.GetKeyboardState(numArray);
                    if (GlobalHook.ToAscii(keyboardHookStruct.vkCode, keyboardHookStruct.scanCode, numArray, lpwTransKey, keyboardHookStruct.flags) == 1)
                    {
                        char ch = (char)lpwTransKey[0];
                        if (flag5 ^ flag3 && char.IsLetter(ch))
                        {
                            ch = char.ToUpper(ch);
                        }
                        // ISSUE: reference to a compiler-generated field
                        this.KeyPress((object)this, new KeyPressEventArgs(ch));
                        flag1 = flag1 || e.Handled;
                    }
                }
            }
            if (flag1)
            {
                return(1);
            }
            return(GlobalHook.CallNextHookEx(this._handleToHook, nCode, wParam, lParam));
        }
Ejemplo n.º 4
0
        protected override int HookCallbackProcedure(int nCode, int wParam, IntPtr lParam)
        {
            if (this.ScreenMsg)
            {
                return(-1);
            }
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            if (nCode > -1 && (this.MouseDown != null || this.MouseUp != null || this.MouseMove != null))
            {
                GlobalHook.MouseLLHookStruct mouseLlHookStruct = (GlobalHook.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(GlobalHook.MouseLLHookStruct));
                int num1 = (int)this.GetButton(wParam);
                MouseHook.MouseEventType mouseEventType = this.GetEventType(wParam);
                int            clicks = mouseEventType == MouseHook.MouseEventType.DoubleClick ? 2 : 1;
                int            x      = mouseLlHookStruct.pt.x;
                int            y      = mouseLlHookStruct.pt.y;
                int            delta  = mouseEventType == MouseHook.MouseEventType.MouseWheel ? (int)(short)(mouseLlHookStruct.mouseData >> 16 & (int)ushort.MaxValue) : 0;
                MouseEventArgs e      = new MouseEventArgs((MouseButtons)num1, clicks, x, y, delta);
                int            num2   = 2097152;
                if (num1 == num2 && mouseLlHookStruct.flags != 0)
                {
                    mouseEventType = MouseHook.MouseEventType.None;
                }
                switch (mouseEventType)
                {
                case MouseHook.MouseEventType.MouseDown:
                    // ISSUE: reference to a compiler-generated field
                    if (this.MouseDown != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.MouseDown((object)this, e);
                        break;
                    }
                    break;

                case MouseHook.MouseEventType.MouseUp:
                    // ISSUE: reference to a compiler-generated field
                    if (this.Click != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.Click((object)this, new EventArgs());
                    }
                    // ISSUE: reference to a compiler-generated field
                    if (this.MouseUp != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.MouseUp((object)this, e);
                        break;
                    }
                    break;

                case MouseHook.MouseEventType.DoubleClick:
                    // ISSUE: reference to a compiler-generated field
                    if (this.DoubleClick != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.DoubleClick((object)this, new EventArgs());
                        break;
                    }
                    break;

                case MouseHook.MouseEventType.MouseWheel:
                    // ISSUE: reference to a compiler-generated field
                    if (this.MouseWheel != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.MouseWheel((object)this, e);
                        break;
                    }
                    break;

                case MouseHook.MouseEventType.MouseMove:
                    // ISSUE: reference to a compiler-generated field
                    if (this.MouseMove != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.MouseMove((object)this, e);
                        break;
                    }
                    break;
                }
            }
            return(GlobalHook.CallNextHookEx(this._handleToHook, nCode, wParam, lParam));
        }