how can I disable windows key in c#?

前端 未结 4 1188
心在旅途
心在旅途 2020-12-10 06:33

How can i disable or lock windows button?

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 07:06

        /// 
        /// Security routines related to the Windows Key on a standard personal computer Keyboard
        /// 
        public static class WindowsKey {
            /// 
            /// Disables the Windows Key
            /// 
            /// May require the current user to logoff or restart the system
            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();
                }
            }
    
            /// 
            /// Enables the Windows Key
            /// 
            /// May require the current user to logoff or restart the system
            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();
                }
            }
        }
    

提交回复
热议问题