5

The Caps Lock key is driving me nuts - I never use it intentionally, but sometimes accidentially press it instead of TAB. My current solution is to remove the button with a screwdriver (no damage, can be placed back if ever needed).

Is there a way to disable the Caps Lock key programmatically on Windows - write a program with a keyboard hook or anything like that? Where do I start?

sharptooth
  • 167,383
  • 100
  • 513
  • 979

3 Answers3

4

To just remap Caps lock (without installing software) on a Windows 2000 or Windows XP machine, I adapted the information found at How to globally map AltGr key to Alt key? as follows. Mapping Caps to null is one of the examples, but you could choose another key to map to as I did. To map caps to null, the registry file is:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00, 00,00,00,00, 02,00,00,00, 1d,00,00,00, 00,00,00,00

Save this as filename.reg and execute, then reboot (or log out and log back in).

I based this on the answer from that page by Tomas Sedovic and on Scan Code Mapper for Windows recommended by Ronald Blaschke. I introduced the spaces to allow me/you to see how the bytes are grouped into words.

Note that I actually used this to map Caps to Ctrl and my second to last group of numbers was "1d,00,3a,00" and I confirmed that this works fine.

Community
  • 1
  • 1
sage
  • 4,863
  • 2
  • 44
  • 47
  • Will users with a password that includes capitals be thwarted from logging in once this registry hack has been executed? – ryyker Jan 10 '23 at 17:15
  • 1
    @ryyker, (with 2011 Windows) this disables "Caps Lock" without disabling the "Shift" keys. Users who like to use "Caps Lock" to type capitals should not disable the "Caps Lock" key. (I no longer use Windows and 12 years have gone by, so I don't know if this still works.) – sage Jan 11 '23 at 20:29
1

The question How to make a Custom Keyboard layout ? describes how to change the functionality of the Caps Lock key.

Community
  • 1
  • 1
andrewdotn
  • 32,721
  • 10
  • 101
  • 130
0

This doesn't do it programmatically, but I believe the OP, or more likely, other users, will find the solution I arrived at much easier; and thus, preferable.

There are handy utilities, or exports of registry keys that can be imported to completely disable it, but once in a blue moon, I do want to type a lot of caps; so I didn't want to completely disable it. I finally came up with a script that seems to work pretty well. No script I made would prevent it from turning on with some mysterious accidental combination (on an early M$ ergo kb), so I decided to map it to a keystroke I never use. The following remaps it to <Ctrl-Pause/Break>. That key chord does nothing normally, but turns on with the following script. Hopefully, it won't be turning accidentally with this; or else I will just disable the key in the registry:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
#NoTrayIcon
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Disable CapsLock and Shift-CapsLock combinations
CapsLock::
+CapsLock::
+^CapsLock::
^CapsLock::

; Uncomment the following lines to also disable the Left Windows Key
;LWin::
;return

; Define the Ctrl-Pause/Break shortcut
^CtrlBreak::
SetCapsLockState % !GetKeyState("CapsLock", "T")
return

I don't expect it to interfere with the normal use of the Pause/Break key (which is just about nothing in Windows). You can compile it into a compact .exe with AutoHotKey too. I quickly found that other combinations of Shift, Ctrl and CapsLock would also trigger CapsLock, but after fixing it in the code, and using it a few days, it's functioning flawlessly. I wasn't sure if disabling the CapsLock key in AHK entirely would also disable the CapsLock state when triggered by another key chord, so I just trapped for these CapsLock-triggering combinations. I have stopped having false CapsLock triggers, and yet CAPS LOCK is still easy go get ;}

CodeLurker
  • 1,248
  • 13
  • 22