Esempio n. 1
0
        private IntPtr KeyboardCloseWindow(
            Int32 Code, IntPtr wParam, IntPtr lParam)

        {
            if (wParam == (IntPtr)WM_KEYUP)
            {
                keyCodeStructure keyStructure = (keyCodeStructure)Marshal.PtrToStructure(lParam, typeof(keyCodeStructure));
                if (Code < 0)
                {
                    return(KeyboardHook.CallNextHookEx(
                               keyBoardHandle, Code, wParam, lParam));
                }
                if (KeyBoardKeyPressed != null && keyStructure.vkCode == ESC_KEY)
                {
                    KeyBoardKeyPressed(this, new EventArgs());

                    //closeWindow.Close();
                    return(KeyboardHook.CallNextHookEx(
                               keyBoardHandle, Code, wParam, lParam));
                }

                else
                {
                    return(KeyboardHook.CallNextHookEx(
                               keyBoardHandle, Code, wParam, lParam));
                }
            }
            else
            {
                return(KeyboardHook.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }
        }
Esempio n. 2
0
        private IntPtr KeyboardHookDelegate(
            Int32 Code, IntPtr wParam, IntPtr lParam)
        {
            if (wParam == (IntPtr)WM_KEYDOWN)
            {
                openSave   = false;
                openSearch = false;
                keyCodeStructure keyStructure = (keyCodeStructure)Marshal.PtrToStructure(lParam, typeof(keyCodeStructure));
                if (keyStructure.vkCode == O_KEY && keyHeld)
                {
                    keyHeldO     = true;
                    keyHeldSaveO = false;
                }

                if (keyStructure.vkCode == W_KEY && keyHeld)
                {
                    keyHeldSaveO = true;
                    keyHeldO     = false;
                }


                if (Code < 0)
                {
                    return(KeyboardHook.CallNextHookEx(
                               keyBoardHandle, Code, wParam, lParam));
                }

                if (KeyBoardKeyPressed != null && (keyHeldO || keyHeldSaveO) && keyHeld)
                {
                    if (keyHeldO)
                    {
                        keyHeld    = false;
                        keyHeldO   = false;
                        openSave   = true;
                        openSearch = false;
                    }
                    if (keyHeldSaveO)
                    {
                        keyHeld    = false;
                        keyHeldO   = false;
                        openSave   = false;
                        openSearch = true;
                    }

                    KeyBoardKeyPressed(this, new EventArgs());
                }
                if (keyStructure.vkCode == CTRL_KEY)
                {
                    keyHeld = true;
                }
                return(KeyboardHook.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }

            else if (wParam == (IntPtr)WM_KEYUP)
            {
                keyCodeStructure keyStructure = (keyCodeStructure)Marshal.PtrToStructure(lParam, typeof(keyCodeStructure));
                if (keyStructure.vkCode == CTRL_KEY)
                {
                    keyHeldO     = false;
                    keyHeld      = false;
                    openSearch   = false;
                    openSave     = false;
                    keyHeldSaveO = false;
                }
                return(KeyboardHook.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }
            else
            {
                return(KeyboardHook.CallNextHookEx(
                           keyBoardHandle, Code, wParam, lParam));
            }
        }