Enable/Disable Windows Key

血红的双手。 提交于 2019-12-13 08:47:49

问题


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.

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).

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 !!


回答1:


MSDN has a page: Disabling Shortcut Keys in Games, which sounds like what you need.

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).

Here's an example of installing a low-level keyboard hook from C#.



来源:https://stackoverflow.com/questions/32516128/enable-disable-windows-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!