返回首页

我想dissable窗口键,打开开始菜单,在我的WPF桌面应用。目的是安全功能,用户不能做任何工作,而开放的应用程序做其他工作的唯一办法是关闭该应用程序。我已经试过命令绑定和关键挂钩和OnPreviewKeydown和OnPreviewKeyUp的,但没有工作。
这是可能的,到dissable WPF中获胜的关键。如果是的话,请帮助一个例子。

我试过到目前为止

protected override void OnPreviewKeyDown(KeyEventArgs e)

        {

            if (e.Key == Key.System) //this will catch alt-tab, alt-esc- alt-f4 etc. BUT NOT CONSISTANTLY!

            {

                e.Handled = true;

                return;

            }

            if (e.Key == Key.LWin||e.Key==Key.RWin)

            {

                e.Handled = true;

                return;

            }

        }

和================================================= ===========

{C}
和================================================= ===========

using System;

 

    public class globalKeyboardHook

    {

        #region Constant, Structure and Delegate Definitions

        /// <summary>

        /// defines the callback type for the hook

        /// </summary>

        public delegate int keyboardHookProc(int code, int wParam, ref keyboardHookStruct lParam);

 

        public struct keyboardHookStruct

        {

            public int vkCode;

            public int scanCode;

            public int flags;

            public int time;

            public int dwExtraInfo;

        }

 

        const int WH_KEYBOARD_LL = 13;

        const int WM_KEYDOWN = 0x100;

        const int WM_KEYUP = 0x101;

        const int WM_SYSKEYDOWN = 0x104;

        const int WM_SYSKEYUP = 0x105;

        #endregion

 

        #region Instance Variables

        /// <summary>

        /// The collections of keys to watch for

        /// </summary>

        public List<Key> HookedKeys = new List<Key>();

        /// <summary>

        /// Handle to the hook, need this to unhook and call the next hook

        /// </summary>

        IntPtr hhook = IntPtr.Zero;

        #endregion

 

        #region Events

 

        /// <summary>

        /// Occurs when one of the hooked keys is pressed

        /// </summary>

        public event KeyEventHandler KeyDown;

 



        /// <summary>

        /// Occurs when one of the hooked keys is released

        /// </summary>

        public event KeyEventHandler KeyUp;

 

        #endregion

 

        #region Constructors and Destructors

 

        /// <summary>

        /// Initializes a new instance of the <see cref="globalKeyboardHook"/> class and installs the keyboard hook.

        /// </summary>

        public globalKeyboardHook()

        {

            hook();

        }

 

        /// <summary>

        /// distructor of hook

        /// </summary>

         globalKeyboardHook()

        {

            unhook();

        }

        #endregion

 

        #region Public Methods

 

        /// <summary>

        /// Installs the global hook

        /// </summary>

        public void hook()

        {

            //keyboardHookProc hook = new keyboardHookProc(hookProc);

            IntPtr hInstance = LoadLibrary("User32");

            hhook = SetWindowsHookExA(WH_KEYBOARD_LL, hookProc, hInstance, 0);

        }

 

        /// <summary>

        /// Uninstalls the global hook

        /// </summary>

        public void unhook()

        {

            UnhookWindowsHookEx(hhook);

        }

 

        /// <summary>

        /// The callback for the keyboard hook

        /// </summary>

        /// <param name="code">The hook code, if it isn't >

回答

评论会员: 时间:2