0X000005B1

Fix ERROR_INVALID_KEYBOARD_HANDLE (0x000005B1) Fast

Windows Errors Intermediate 👁 8 views 📅 Jun 2, 2026

This error means Windows can't find the keyboard layout you're trying to use. Happens after language pack updates or third-party keyboard tools. Here's how to fix it.

Quick Answer

Delete the corrupted keyboard layout profile from the registry or reinstall the language pack. The culprit is almost always a stale layout pointer left behind after a language update.

Context: Why This Happens

Windows stores keyboard layouts in the registry under HKEY_CURRENT_USER\Keyboard Layout\Preload. Each layout gets a 4-digit hex ID that maps to a DLL file in C:\Windows\System32. When that DLL gets removed, renamed, or corrupted — usually after a language pack update or a third-party tool like SharpKeys or Microsoft Keyboard Layout Creator — the handle becomes invalid. The result? That 0x000005B1 error pops up when you try to switch layouts or when a program queries the active keyboard layout.

This happens most often after a Windows Feature Update (like from 22H2 to 23H2). The update might drop a language pack but leave the old registry entry behind. I've also seen it after uninstalling a keyboard remapping tool without cleaning up its registry keys.

Fix Steps: Clear and Rebuild the Keyboard Layout List

  1. Open Registry Editor. Press Win+R, type regedit, hit Enter. Go to HKEY_CURRENT_USER\Keyboard Layout\Preload. (Backup first: right-click the Preload key, select Export.)
  2. Delete all subkeys except the default one. You'll see keys named 1, 2, 3, etc., with values like 00000409 (US English). Right-click and delete everything under Preload. Don't delete the Preload key itself — just its children.
  3. Go to the Substitutes key. Navigate to HKEY_CURRENT_USER\Keyboard Layout\Substitutes and delete all subkeys there too. This is where stale layout mappings get left behind.
  4. Restart your PC. A reboot forces Windows to rebuild the layout list from scratch using the default locale.
  5. Re-add your preferred layout. Go to Settings > Time & Language > Language & Region. Click the three dots next to your language, choose Language Options, then hit Add a keyboard. Pick your layout (e.g., US QWERTY).

If That Didn't Work: Alternative Fixes

Sometimes the registry cleanup isn't enough. Here's what else to try:

  • Repair the language pack. Run sfc /scannow from an admin Command Prompt. Then run DISM /Online /Cleanup-Image /RestoreHealth. This fixes system file corruption that might affect the layout DLLs.
  • Remove and reinstall the entire language. In Settings > Time & Language > Language & Region, remove the language that's linked to the broken layout. Add it back fresh — this resets all keyboard profiles cleanly.
  • Check for third-party keyboard tools. Uninstall anything like KeyTweak, AutoHotkey, or Microsoft Keyboard Layout Creator. These often write custom layouts to %LocalAppData%\Microsoft\Input\ and can leave orphaned entries. Reinstall them later if you need them.
  • Kill the ctfmon process. Open Task Manager, find ctfmon.exe or CTF Loader, end it. Then restart the Touch Keyboard and Handwriting Panel service (services.msc). This sometimes resets the language bar state.

Prevention Tip: Clean Up Before Language Updates

Before you install a Windows Feature Update, remove any custom keyboard layouts you've added manually. Go to %LocalAppData%\Microsoft\Input\ and delete old layout folders. This keeps the registry clean and stops the update from leaving dangling references. I lost count of how many times I've seen this exact error after a semi-annual update — five minutes of cleanup saves an hour of debugging.

Was this solution helpful?