How to Disable Keyboard Keys in Windows 11 with AutoHotkey (or PowerToys)

Craig Snyder
·
10 min read

Help Desk Geek is reader-supported. We may earn a commission when you buy through links on our site. Learn more.

You hit the Windows key by accident mid-game and your fullscreen app drops straight to the desktop, or Caps Lock turns your password into shouting again. You can switch off any key in Windows 11 or Windows 10 with Microsoft PowerToys, a one-line AutoHotkey v2 script, or a registry mapping.

MethodBest forNeeds to keep running?Difficulty
PowerToys Keyboard ManagerTurning off a key with no codeYesEasy
AutoHotkey v2 scriptSeveral keys, per-app rules, quick on/offYesEasy to Medium
Registry Scancode MapA permanent change for every user on the PCNoHard

Fix #1: Disable the key with PowerToys Keyboard Manager

PowerToys Keyboard Manager is Microsoft’s free tool for remapping keys and shortcuts. If you’d rather click than script, start here.

  1. Install Microsoft PowerToys from the Microsoft Store. If the Store is blocked on your PC, Microsoft also supports installing it with WinGet or from GitHub.
  2. Open PowerToys Settings.
  3. Select Keyboard Manager in the sidebar.
  4. Turn on Enable Keyboard Manager.
  5. Select Remap a key.
  6. Select Add key remapping.
  7. In the left column (labeled Select or similar), pick the key you want to turn off.
  8. In the right column (labeled To send or similar), choose Disable (shown as Disabled in the new editor). The exact label for the no-action option can vary between PowerToys releases.
  9. Click OK.

Starting with PowerToys 0.100, new installations open the redesigned editor by default. That editor gained a Disabled action in PowerToys 0.99, so current releases include it; only older builds of the new editor lacked it. If you’re on an older build and can’t find it, turn off Use the new editor on the Keyboard Manager page to switch to the legacy editor, as described in Microsoft’s Keyboard Manager documentation. If neither editor offers it, use the AutoHotkey method in Fix #2.

PowerToys Keyboard Manager "Remap keys" dialog with Caps Lock in the left column and Disable selected in the right column, OK button visible

Press the key. Nothing should happen.

The remap only works while PowerToys is running in the background with the Keyboard Manager module turned on. You don’t need to keep the PowerToys Settings window open, but if you exit PowerToys from the notification area or switch off Keyboard Manager, the key comes back.

If the key still works inside an app you’ve launched as administrator, Microsoft says remapping won’t apply to elevated windows unless you run PowerToys as administrator. That gives PowerToys admin rights for as long as it runs, so only turn it on if you actually need the remap inside elevated apps.

Fix #2: Disable keys with an AutoHotkey v2 script

AutoHotkey is a free scripting tool for Windows hotkeys and automation. It’s more flexible than PowerToys, and the script to kill a key is one line long.

Step 1: Install AutoHotkey v2

  1. Go to the AutoHotkey download page and download the current v2 release.
  2. Run the installer and accept the default options.
AutoHotkey v2 installer window on Windows 11 with the Install button visible and default options selected

Write every script in v2 syntax. Plenty of older guides online use v1 commands, and those throw errors or silently fail in v2.

Step 2: Find the key’s name

AutoHotkey refers to keys by name. Check the list of supported key names for the one you want.

AutoHotkey v2 documentation List of Keys page with the CapsLock entry highlighted

Common ones:

  • CapsLock for Caps Lock
  • LWin and RWin for the left and right Windows keys
  • LAlt and RAlt for the left and right Alt keys
  • AppsKey for the Menu (context-menu) key
  • Insert, F1 through F24, Tab, Escape, Delete

Use these names. Don’t try to type the literal character.

Step 3: Create the script

  1. Right-click an empty spot in a folder you’ll keep, such as Documents\Scripts.
  2. Select New > AutoHotkey Script.
  3. Name it something clear, like DisableKeys.ahk.
  4. Right-click the file and choose Edit Script. If that option isn’t there, open the file in Notepad.
  5. Add one line per key you want to disable. To kill Caps Lock:
#Requires AutoHotkey v2.0
CapsLock::Return

Keep #Requires AutoHotkey v2.0 as the first line of every script. If v1 is also installed, it makes AutoHotkey run the file with v2 or show a clear error instead of misbehaving.

To kill both Windows keys:

#Requires AutoHotkey v2.0
LWin::Return
RWin::Return
Windows 11 Notepad with an AutoHotkey v2 script containing CapsLock::Return, LWin::Return, and RWin::Return on separate lines

The format is OriginKey::DestinationKey. Using Return as the destination tells AutoHotkey to do nothing, which is exactly what you want. The AutoHotkey v2 remapping docs use RWin::Return as their own example.

I’d skip disabling Alt entirely unless it’s actively wrecking something. It breaks menus, Alt + Tab, and plenty of app shortcuts. If you must, disable only LAlt and leave RAlt working.

  1. Save the file.

If you wrote the script in Notepad from scratch, set Save as type to All files and make sure the name ends in .ahk. A file saved as DisableKeys.ahk.txt won’t run.

Windows 11 Notepad Save As dialog with Save as type set to All files and the file name DisableKeys.ahk entered

Step 4: Run the script

  1. Open File Explorer and go to the folder with your script. The file should show the green AutoHotkey “H” icon.
Windows 11 File Explorer showing DisableKeys.ahk with the green AutoHotkey H icon in the Documents Scripts folder
  1. Double-click the file.
  2. Check the notification area for the green AutoHotkey icon. Click the up arrow next to the clock if it’s hidden.
Windows 11 taskbar notification area overflow expanded showing the green AutoHotkey H tray icon

Press the disabled key. If it does nothing, you’re done.

Step 5: Pause, reload, or stop the script

Right-click the AutoHotkey tray icon to control the script.

Right-click menu of the AutoHotkey v2 tray icon on Windows 11 showing Reload Script, Edit Script, Suspend Hotkeys, and Exit
  • Reload Script applies changes after you edit and save the file. Forgetting this step is a common reason a freshly edited script “doesn’t work.”
  • Suspend Hotkeys turns your keys back on temporarily. The tray icon changes to show it’s suspended. Select it again to re-disable them.
  • Exit stops the script completely.

Fix #3: Start the AutoHotkey script with Windows

The script stops when you restart your PC. A shortcut in your Startup folder relaunches it every time you sign in.

  1. Press Windows + R to open the Run dialog.
  2. Type shell:startup and press Enter. Your Startup folder opens in File Explorer.
Windows 11 Run dialog with shell:startup typed in the Open field and the OK button visible
  1. Open a second File Explorer window and go to the folder where your .ahk file lives.
  2. Right-click the script and select Show more options > Create shortcut. On Windows 10, Create shortcut is right in the menu.
  3. Drag the new shortcut into the Startup folder.
Windows 11 File Explorer Startup folder containing a shortcut to DisableKeys.ahk

Because the Startup folder only holds a shortcut, you can keep editing the original file in place. To undo it, delete the shortcut.

Fix #4: Disable a key only in one app or game

Maybe you want the Windows key dead in your game but working everywhere else. AutoHotkey v2 handles this with #HotIf.

  1. Find the app’s executable name. Open Task Manager, right-click the app, and select Go to details. The highlighted entry (like ExampleGame.exe) is the name you want. The window title usually isn’t the same thing.
  2. Edit your script and wrap the remaps like this:
#Requires AutoHotkey v2.0
#HotIf WinActive("ahk_exe ExampleGame.exe")
LWin::Return
RWin::Return
#HotIf
  1. Replace ExampleGame.exe with the real executable name.
  2. Save the file, then right-click the tray icon and select Reload Script.

The Windows keys should now do nothing while that app is in the foreground, as long as AutoHotkey can receive the app’s input. Switch to another window and they work normally. If the keys still work in the game, see the elevation and input notes under “When the fixes don’t work” below.

Microsoft documents a Target app field for PowerToys shortcut remaps, but its key-remap instructions don’t include a per-app option, so AutoHotkey is the more dependable tool for a per-game key block. Microsoft’s own Keyboard Manager documentation also lists, under Known Issues, that Keyboard Manager “shouldn’t be used when playing video games” because its interception of key presses “will impact the FPS.”

Fix #5: Disable a key permanently with the registry Scancode Map

This writes a machine-level mapping under HKLM that Windows loads at startup, so nothing has to keep running in the background. It normally affects every user who signs in to the PC, but existing mappings, keyboard utilities, Remote Desktop sessions, and firmware-level key handling can still change how a key behaves.

It’s also the hardest method to undo if you get it wrong. Your main safety net is the backup from step 2: after exporting it, confirm the .reg file is on your desktop and copy it somewhere safe before you change anything. A spare USB keyboard is a useful backup in case you disable the wrong key.

  1. Right-click Start and select Terminal (Admin). On Windows 10, choose Windows PowerShell (Admin).
  2. Back up the key by running reg export "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" "$env:USERPROFILE\Desktop\KeyboardLayout-backup.reg". You should see “The operation completed successfully.”
  3. Check for an existing mapping by running reg query "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map". If it prints a value instead of an error saying the value can’t be found, this PC already has a key remap (often from a keyboard utility or an IT policy). The next command would overwrite it, so stop here and use PowerToys or AutoHotkey instead.
  4. To disable Caps Lock, run reg add "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /t REG_BINARY /d 00000000000000000200000000003A0000000000 /f.
Windows Terminal running as administrator showing the reg add Scancode Map command and "The operation completed successfully" message
  1. Restart your PC.

After the restart, Caps Lock should be disabled throughout normal Windows sessions. Behavior on the sign-in screen can vary by device and input path. The change is system-wide, and it’s reversible as long as you follow the check in step 3 or keep the backup from step 2. To bring the key back, run reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /f in an admin terminal and restart again.

Step 3 confirmed there was no earlier mapping, so deleting the value returns the keyboard to its default layout. If you skipped that check and the backup file from step 2 contains a "Scancode Map" line, run reg import "$env:USERPROFILE\Desktop\KeyboardLayout-backup.reg" instead of deleting the value, then restart to restore the original mapping.

Don’t hand-edit other binary mappings unless you know the exact scan codes. A malformed value can disable the wrong key. And never map away Enter, Escape, or Ctrl without a way back in.

When the fixes don’t work

The Windows key still works in a game. One common cause is that the game runs as administrator while AutoHotkey or PowerToys doesn’t. Microsoft documents this limitation for PowerToys. AutoHotkey is commonly affected by the same Windows integrity-level restriction: a script that isn’t elevated usually can’t intercept keys meant for an elevated window, though results vary by app and how it reads input. The AutoHotkey FAQ on User Account Control covers the workarounds.

Running either tool as administrator gives it, and anything it launches, full admin rights, so do it only for a trusted script or setup and only while you need it. Also check whether you blocked LWin but you’re actually hitting RWin. A gaming keyboard with a Windows-key lock or Game Mode switch handles this in hardware, and its companion software can override your remaps.

You can’t block Ctrl+Alt+Delete. Windows protects that combination on purpose, and PowerToys lists it as reserved.

The Fn key won’t disable. Most laptops handle Fn in firmware before Windows ever sees it. AutoHotkey can catch the resulting F-key or media key, but not Fn itself. A programmable keyboard or the manufacturer’s own utility is usually the way to go, and some laptops also offer an Fn-lock or function-key setting in the BIOS/UEFI.

Nothing works in BIOS or over Remote Desktop. These tools only run inside Windows, and Remote Desktop processes some keys locally. Test your exact setup before relying on it.

Conclusion

For a single annoying key, Fix #1 (PowerToys) is the quickest to set up. AutoHotkey v2 (Fix #2) is my pick if you want per-game rules or a quick suspend from the tray. If a “disabled” key keeps working in one specific app, check admin privileges and your keyboard’s own software before reaching for the registry.