Exemplo n.º 1
0
        } // KeyboardHook

        #endregion

        #region Hook Callback Method

        /// <summary>
        /// Processes the key event captured by the hook.
        /// </summary>
        private IntPtr HookCallback(int nCode, IntPtr wParam, ref KeyboadHookStruct lParam)
        {
            // This is an easy way to change from a key press behavior to a key down behavior.
            if (lParam.Flags != lastParameter.Flags || lParam.VkCode != lastParameter.VkCode)
            {
                // If the key is disable or has a special function.
                if (lParam.VkCode == 91 || lParam.VkCode == 92 ||  // Win
                    (lParam.VkCode == 13) ||  // Alt-Enter (does not work properly so I made a fix)
                    lParam.VkCode == 44) // Print Screen
                {
                    if (lParam.VkCode == 44)
                    {
                        ScreenshotCapturer.MakeScreenshot = true;
                    }
                    KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
                    if (keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt))
                    {
                        Screen.ToggleFullscreen();
                    }

                    // Store current parameter.
                    lastParameter = lParam;
                    if (lParam.VkCode != 13)
                        return (IntPtr)1;
                }
            }
            // Store current parameter.
            lastParameter = lParam;
            // if the key is allowed...
            return NativeMethods.CallNextHookEx(hookId, nCode, wParam, ref lParam);
        } // HookCallback
Exemplo n.º 2
0
 public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref KeyboadHookStruct lParam);