How can i disable or lock windows button?
Click the plus button, then click the “Key” drop-down menu. Scroll down to “Win” and select that option. Now click the “Mapped To” drop-down menu and choose Disable. Click OK to confirm.
Please, press Fn + F6 to activate or deactivate Windows key. This procedure is compatible with computers and notebooks, regardless which brand are you using. Also, try pressing “Fn + Windows” key which can sometimes get it working again.
Press Windows Key + R and enter gpedit. Press Enter or click OK. Now navigate to the User Configuration > Administrative Templates > Windows Components > File Explorer in the left pane. In the right pane, locate and double click Turn off Windows Key hotkeys option.
Using the windows hooks is a lot cleaner than modifying the registry. Additionally, sometimes people have setup personalized scancode maps of their own, and overwriting them is not a very kind thing to do.
To use the windows key hook functions you need to DllImport a couple winapi functions:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(int idHook, HookHandlerDelegate lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode);
A fairly complete explanation and walkthrough can be found on CodeProject. Here is a direct link to a self contained class file from that example that does everything (To get it to compile clean if you are using WPF will require you to manually reference System.Windows.Forms dll or just changing the 'System.Windows.Forms.Keys' reference to System.Windows.Input.Key should work).
Remember to call UnhookWindowsHookEx() (the class does this in Dispose()) to unhook your captures or people will hate you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With