Ejemplo n.º 1
0
        // Token: 0x0600006C RID: 108 RVA: 0x00002D10 File Offset: 0x00000F10
        private static int KeyboardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            bool flag = false;

            if (nCode >= 0)
            {
                HookManager.KeyboardHookStruct keyboardHookStruct = (HookManager.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.KeyboardHookStruct));
                if (HookManager.s_KeyDown != null && (wParam == 256 || wParam == 260))
                {
                    KeyEventArgs keyEventArgs = new KeyEventArgs((Keys)keyboardHookStruct.VirtualKeyCode);
                    HookManager.s_KeyDown(null, keyEventArgs);
                    flag = keyEventArgs.Handled;
                }
                if (HookManager.s_KeyPress != null && wParam == 256)
                {
                    bool   flag2 = (HookManager.GetKeyState(16) & 128) == 128;
                    bool   flag3 = HookManager.GetKeyState(20) != 0;
                    byte[] array = new byte[256];
                    HookManager.GetKeyboardState(array);
                    byte[] array2 = new byte[2];
                    if (HookManager.ToAscii(keyboardHookStruct.VirtualKeyCode, keyboardHookStruct.ScanCode, array, array2, keyboardHookStruct.Flags) == 1)
                    {
                        char c = (char)array2[0];
                        if ((flag3 ^ flag2) && char.IsLetter(c))
                        {
                            c = char.ToUpper(c);
                        }
                        KeyPressEventArgs keyPressEventArgs = new KeyPressEventArgs(c);
                        HookManager.s_KeyPress(null, keyPressEventArgs);
                        flag = (flag || keyPressEventArgs.Handled);
                    }
                }
                if (HookManager.s_KeyUp != null && (wParam == 257 || wParam == 261))
                {
                    KeyEventArgs keyEventArgs2 = new KeyEventArgs((Keys)keyboardHookStruct.VirtualKeyCode);
                    HookManager.s_KeyUp(null, keyEventArgs2);
                    flag = (flag || keyEventArgs2.Handled);
                }
            }
            int result;

            if (flag)
            {
                result = -1;
            }
            else
            {
                result = HookManager.CallNextHookEx(HookManager.s_KeyboardHookHandle, nCode, wParam, lParam);
            }
            return(result);
        }
Ejemplo n.º 2
0
 private static void EnsureSubscribedToGlobalKeyboardEvents()
 {
     if (HookManager.s_KeyboardHookHandle == 0)
     {
         HookManager.s_KeyboardDelegate = new HookManager.HookProc(HookManager.KeyboardHookProc);
         Process       currentProcess = Process.GetCurrentProcess();
         ProcessModule mainModule     = currentProcess.MainModule;
         IntPtr        moduleHandle   = HookManager.GetModuleHandle(mainModule.ModuleName);
         HookManager.s_KeyboardHookHandle = HookManager.SetWindowsHookEx(13, HookManager.s_KeyboardDelegate, moduleHandle, 0);
         if (HookManager.s_KeyboardHookHandle == 0)
         {
             int lastWin32Error = Marshal.GetLastWin32Error();
         }
     }
 }
Ejemplo n.º 3
0
        private static void ForceUnsunscribeFromGlobalKeyboardEvents()
        {
            if (HookManager.s_KeyboardHookHandle == 0)
            {
                return;
            }
            int num = HookManager.UnhookWindowsHookEx(HookManager.s_KeyboardHookHandle);

            HookManager.s_KeyboardHookHandle = 0;
            HookManager.s_KeyboardDelegate   = (HookManager.HookProc)null;
            if (num == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 4
0
        private static int KeyboardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            bool flag1 = false;

            if (nCode >= 0)
            {
                HookManager.KeyboardHookStruct structure = (HookManager.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.KeyboardHookStruct));
                if (HookManager.s_KeyDown != null && (wParam == 256 || wParam == 260))
                {
                    KeyEventArgs e = new KeyEventArgs((Keys)structure.VirtualKeyCode);
                    HookManager.s_KeyDown((object)null, e);
                    flag1 = e.Handled;
                }
                if (HookManager.s_KeyPress != null && wParam == 256)
                {
                    bool   flag2    = ((int)HookManager.GetKeyState(16) & 128) == 128;
                    bool   flag3    = (int)HookManager.GetKeyState(20) != 0;
                    byte[] numArray = new byte[256];
                    HookManager.GetKeyboardState(numArray);
                    byte[] lpwTransKey = new byte[2];
                    if (HookManager.ToAscii(structure.VirtualKeyCode, structure.ScanCode, numArray, lpwTransKey, structure.Flags) == 1)
                    {
                        char upper = (char)lpwTransKey[0];
                        if (flag3 ^ flag2 && char.IsLetter(upper))
                        {
                            upper = char.ToUpper(upper);
                        }
                        KeyPressEventArgs e = new KeyPressEventArgs(upper);
                        HookManager.s_KeyPress((object)null, e);
                        flag1 = flag1 || e.Handled;
                    }
                }
                if (HookManager.s_KeyUp != null && (wParam == 257 || wParam == 261))
                {
                    KeyEventArgs e = new KeyEventArgs((Keys)structure.VirtualKeyCode);
                    HookManager.s_KeyUp((object)null, e);
                    flag1 = flag1 || e.Handled;
                }
            }
            if (flag1)
            {
                return(-1);
            }
            return(HookManager.CallNextHookEx(HookManager.s_KeyboardHookHandle, nCode, wParam, lParam));
        }
Ejemplo n.º 5
0
 // Token: 0x0600006E RID: 110 RVA: 0x00003184 File Offset: 0x00001384
 private static void OnMouseUp(object sender, MouseEventArgs e)
 {
     if (e.Clicks >= 1)
     {
         if (e.Button.Equals(HookManager.s_PrevClickedButton))
         {
             if (HookManager.s_MouseDoubleClick != null)
             {
                 HookManager.s_MouseDoubleClick(null, e);
             }
             HookManager.s_DoubleClickTimer.Enabled = false;
             HookManager.s_PrevClickedButton        = MouseButtons.None;
         }
         else
         {
             HookManager.s_DoubleClickTimer.Enabled = true;
             HookManager.s_PrevClickedButton        = e.Button;
         }
     }
 }
Ejemplo n.º 6
0
        // Token: 0x0600006D RID: 109 RVA: 0x00002EE0 File Offset: 0x000010E0
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                HookManager.MouseLLHookStruct mouseLLHookStruct = (HookManager.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.MouseLLHookStruct));
                MouseButtons buttons = MouseButtons.None;
                short        num     = 0;
                int          num2    = 0;
                bool         flag    = false;
                bool         flag2   = false;
                switch (wParam)
                {
                case 513:
                    flag    = true;
                    buttons = MouseButtons.Left;
                    num2    = 1;
                    break;

                case 514:
                    flag2   = true;
                    buttons = MouseButtons.Left;
                    num2    = 1;
                    break;

                case 515:
                    buttons = MouseButtons.Left;
                    num2    = 2;
                    break;

                case 516:
                    flag    = true;
                    buttons = MouseButtons.Right;
                    num2    = 1;
                    break;

                case 517:
                    flag2   = true;
                    buttons = MouseButtons.Right;
                    num2    = 1;
                    break;

                case 518:
                    buttons = MouseButtons.Right;
                    num2    = 2;
                    break;

                case 522:
                    num = (short)(mouseLLHookStruct.MouseData >> 16 & 65535);
                    break;
                }
                MouseEventExtArgs mouseEventExtArgs = new MouseEventExtArgs(buttons, num2, mouseLLHookStruct.Point.X, mouseLLHookStruct.Point.Y, (int)num);
                if (HookManager.s_MouseUp != null && flag2)
                {
                    HookManager.s_MouseUp(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseDown != null && flag)
                {
                    HookManager.s_MouseDown(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseClick != null && num2 > 0)
                {
                    HookManager.s_MouseClick(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseClickExt != null && num2 > 0)
                {
                    HookManager.s_MouseClickExt(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseDoubleClick != null && num2 == 2)
                {
                    HookManager.s_MouseDoubleClick(null, mouseEventExtArgs);
                }
                if (HookManager.s_MouseWheel != null && num != 0)
                {
                    HookManager.s_MouseWheel(null, mouseEventExtArgs);
                }
                if ((HookManager.s_MouseMove != null || HookManager.s_MouseMoveExt != null) && (HookManager.m_OldX != mouseLLHookStruct.Point.X || HookManager.m_OldY != mouseLLHookStruct.Point.Y))
                {
                    HookManager.m_OldX = mouseLLHookStruct.Point.X;
                    HookManager.m_OldY = mouseLLHookStruct.Point.Y;
                    if (HookManager.s_MouseMove != null)
                    {
                        HookManager.s_MouseMove(null, mouseEventExtArgs);
                    }
                    if (HookManager.s_MouseMoveExt != null)
                    {
                        HookManager.s_MouseMoveExt(null, mouseEventExtArgs);
                    }
                }
                if (mouseEventExtArgs.Handled)
                {
                    return(-1);
                }
            }
            return(HookManager.CallNextHookEx(HookManager.s_MouseHookHandle, nCode, wParam, lParam));
        }
Ejemplo n.º 7
0
        private static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                HookManager.MouseLLHookStruct structure = (HookManager.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(HookManager.MouseLLHookStruct));
                MouseButtons buttons = MouseButtons.None;
                short        num     = 0;
                int          clicks  = 0;
                bool         flag1   = false;
                bool         flag2   = false;
                switch (wParam)
                {
                case 513:
                    flag1   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 514:
                    flag2   = true;
                    buttons = MouseButtons.Left;
                    clicks  = 1;
                    break;

                case 515:
                    buttons = MouseButtons.Left;
                    clicks  = 2;
                    break;

                case 516:
                    flag1   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 517:
                    flag2   = true;
                    buttons = MouseButtons.Right;
                    clicks  = 1;
                    break;

                case 518:
                    buttons = MouseButtons.Right;
                    clicks  = 2;
                    break;

                case 522:
                    num = (short)(structure.MouseData >> 16 & (int)ushort.MaxValue);
                    break;
                }
                MouseEventExtArgs e = new MouseEventExtArgs(buttons, clicks, structure.Point.X, structure.Point.Y, (int)num);
                if (HookManager.s_MouseUp != null && flag2)
                {
                    HookManager.s_MouseUp((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseDown != null && flag1)
                {
                    HookManager.s_MouseDown((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClick != null && clicks > 0)
                {
                    HookManager.s_MouseClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseClickExt != null && clicks > 0)
                {
                    HookManager.s_MouseClickExt((object)null, e);
                }
                if (HookManager.s_MouseDoubleClick != null && clicks == 2)
                {
                    HookManager.s_MouseDoubleClick((object)null, (MouseEventArgs)e);
                }
                if (HookManager.s_MouseWheel != null && (int)num != 0)
                {
                    HookManager.s_MouseWheel((object)null, (MouseEventArgs)e);
                }
                if ((HookManager.s_MouseMove != null || HookManager.s_MouseMoveExt != null) && (HookManager.m_OldX != structure.Point.X || HookManager.m_OldY != structure.Point.Y))
                {
                    HookManager.m_OldX = structure.Point.X;
                    HookManager.m_OldY = structure.Point.Y;
                    if (HookManager.s_MouseMove != null)
                    {
                        HookManager.s_MouseMove((object)null, (MouseEventArgs)e);
                    }
                    if (HookManager.s_MouseMoveExt != null)
                    {
                        HookManager.s_MouseMoveExt((object)null, e);
                    }
                }
                if (e.Handled)
                {
                    return(-1);
                }
            }
            return(HookManager.CallNextHookEx(HookManager.s_MouseHookHandle, nCode, wParam, lParam));
        }