Exemple #1
0
        IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool block = false;

            if (ignore)
            {
                goto chain;
            }

            bool pressed = wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN;

            if (nCode >= 0 && pressed || wParam == (IntPtr)WM_KEYUP)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                int sc     = Marshal.ReadInt32(lParam, 8);

                if (dead || deadkeys.Contains(vkCode))
                {
                    dead = !dead;
                    goto chain;
                }

                string typed = MapKey((uint)vkCode, (uint)sc);
                block = KeyReceived((Keys)vkCode, typed, pressed);
            }

chain:
            var next = WindowsAPI.CallNextHookEx(hookId, nCode, wParam, lParam);

            return(block ? new IntPtr(1) : next);
        }
Exemple #2
0
        private IntPtr MouseHook(int code, IntPtr wparam, IntPtr lparam)
        {
            MOUSEHOOKSTRUCT mh = (MOUSEHOOKSTRUCT )Marshal.PtrToStructure(lparam, typeof(MOUSEHOOKSTRUCT));

            // if user set focus on edit control embedded by us then do not open DropDown box
            if (mh.hwnd == Handle &&
                wparam == (IntPtr)Msg.WM_LBUTTONDOWN &&
                m_bDropDown == false && ReadOnly == false)
            {
                m_bSkipClick = true;
            }

            return(WindowsAPI.CallNextHookEx(m_mouseHookHandle, code, wparam, lparam));
        }
Exemple #3
0
        IntPtr MouseHook(int code, IntPtr wparam, IntPtr lparam)
        {
            MOUSEHOOKSTRUCT mh = (MOUSEHOOKSTRUCT )Marshal.PtrToStructure(lparam, typeof(MOUSEHOOKSTRUCT));

            if (mh.hwnd != Handle && !DroppedDown &&
                (wparam == (IntPtr)Msg.WM_LBUTTONDOWN || wparam == (IntPtr)Msg.WM_RBUTTONDOWN) ||
                wparam == (IntPtr)Msg.WM_NCLBUTTONDOWN)
            {
                // Loose focus
                WindowsAPI.SetFocus(IntPtr.Zero);
            }
            else if (mh.hwnd != Handle && !DroppedDown &&
                     (wparam == (IntPtr)Msg.WM_LBUTTONUP || wparam == (IntPtr)Msg.WM_RBUTTONUP) ||
                     wparam == (IntPtr)Msg.WM_NCLBUTTONUP)
            {
                WindowsAPI.SetFocus(IntPtr.Zero);
            }
            return(WindowsAPI.CallNextHookEx(mouseHookHandle, code, wparam, lparam));
        }
Exemple #4
0
    private static int LowLevelHookProc(int code, IntPtr wParam, IntPtr lParam) // lParam is KBDLLHookStruct and wParam is a keyState
    {
        if (code >= 0)
        {
            var kb       = KBDLLHookStruct.CreateStruct(lParam);
            var keyState = (KeyState)wParam;
            var key      = (Key)kb.vkCode;

            if (keyState == KeyState.KeyDown || keyState == KeyState.SysKeyDown)
            {
                OnKeyDown(key);
            }
            else
            {
                OnKeyUp(key);
            }
        }
        return(WindowsAPI.CallNextHookEx(hookId, code, wParam, lParam));
    }