启用/禁用Windows密钥

时间:2015-09-11 05:31:48

标签: c# windows windows-applications

我在Keyboard中使用以下代码启用/禁用Windows键。它工作正常。

    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();
            }
        }
    }

但如果我使用上面的代码,那么在系统重新启动后会影响启用/禁用。

我需要在C#上点击Button来执行此操作。这意味着如果我从上面的代码中调用Disable函数,我需要立即禁用Windows键(不会影响重启后)。

如果我在按钮单击上面的代码中调用启用功能,请单击“我需要启用Windows密钥”。

我该怎么做?在此先感谢!!

0 个答案:

没有答案
相关问题