问题描述
我使用以下代码启用/禁用键盘中的 Windows 键.它工作正常.
I use the following code for Enable/Disable windows key in Keyboard.It was working fine .
public static class WindowsKey {
public static void Disable() {
RegistryKey key = null;
try {
key = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Keyboard Layout", true);
byte[] binary = new byte[] {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x03,
0x00,
0x00,
0x00,
0x00,
0x00,
0x5B,
0xE0,
0x00,
0x00,
0x5C,
0xE0,
0x00,
0x00,
0x00,
0x00
};
key.SetValue("Scancode Map", binary, RegistryValueKind.Binary);
}
catch (System.Exception ex) {
Debug.Assert(false, ex.ToString());
}
finally {
key.Close();
}
}
public static void Enable() {
RegistryKey key = null;
try {
key = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Keyboard Layout", true);
key.DeleteValue("Scancode Map", true);
}
catch (System.Exception ex) {
Debug.Assert(false, ex.ToString());
}
finally {
key.Close();
}
}
}
但是如果我使用上面的代码,它会在系统重新启动后影响启用/禁用.
But If I use the above code it was affect enable/disable after the System getting Restarted.
我需要在 C# 的 Button 单击上执行此操作.这意味着如果我从上面的代码中调用 Disable 函数,我需要立即禁用 Windows 键(不影响重启后).
I need to do with this on Button click from C#.Which means If I call the Disable function from the above code I need to disable windows key Immediately(not affect After Restart).
如果我从上面的 Button 单击代码中调用 Enable 函数,我需要启用 Windows Key.
If I call Enable function from the above code in Button click I need to Enable Windows Key.
我该怎么做??提前致谢!!
How can I do this?? Thanks in Advance !!
推荐答案
MSDN 有一个页面:禁用游戏中的快捷键,听起来正是您所需要的.
MSDN has a page: Disabling Shortcut Keys in Games, which sounds like what you need.
本质上,您安装了一个低级键盘钩子来吃掉不需要的键.您还需要处理 WM_ACTIVATEAPP
消息以适当地启用/禁用挂钩(否则,当您不是活动应用程序时,您会吃掉密钥).
Essentially you install a low-level keyboard hook to eat the undesired keys. You also need to handle the WM_ACTIVATEAPP
message to enable/disable the hook appropriately (otherwise you'll eat the keys when you're not the active application).
这是安装来自 C# 的低级键盘钩子.
Here's an example of installing a low-level keyboard hook from C#.
这篇关于启用/禁用 Windows 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!