Map capslock to control in windows 10

89

43

In windows 8 I used to remap my capslock key to control using the registry script

REGEDIT4

[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,3a,00,00,00,00,00

After having upgraded to window 10, this does not work anymore. How can it be done?

Chiel ten Brinke

Posted 2015-08-02T12:36:09.643

Reputation: 1 165

Note this only remaps Caps Lock to another Ctrl key. I want them swapped, so I used the instructions here to tweak the script above: https://superuser.com/a/1202601/315584

– jia103 – 2017-09-20T15:00:46.360

Answers

90

Did you remember to re-boot? Seems to work fine for me, just like in 7 and 8.

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,3a,00,00,00,00,00

hugh

Posted 2015-08-02T12:36:09.643

Reputation: 916

9The issue for me was that the Windows 10 upgrade reset my caps lock mapping. But doing it again the same way worked after another restart. – Jack O'Connor – 2015-12-01T02:48:13.127

39If anyone else like me needs the final piece of the puzzle: paste the above into a new text file, save it with the .reg extension, double click the file to apply the changes to the registry, then reboot. – Mike Niebling – 2016-09-06T00:00:22.883

4How do you map it back to Caps Lock afterwards? – Ehtesh Choudhury – 2016-12-01T01:36:56.333

7@EhteshChoudhury you can delete the "Scancode Map" entry under the registry key, reboot, and default behavior will be restored. – bojolais – 2017-04-11T19:16:38.207

I only had to logout and login again, didn't have to reboot (win 10) – piec – 2020-02-07T15:10:06.800

92

In case anyone needed this done via PowerShell:

$hexified = "00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00".Split(',') | % { "0x$_"};

$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout';

New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified);

Run it as Administrator and reboot.

Frison Alexander

Posted 2015-08-02T12:36:09.643

Reputation: 1 021

19Have an upvote for giving a Linux-like "copy&paste into shell" answer! – mikezter – 2017-09-08T08:44:16.273

3Seriously. I miss having *initrc scripts. Thanks. – stewSquared – 2018-04-24T20:18:08.173

8You sir, have made using Windows today a slightly less miserable experience. For that, I thank you. – binarymason – 2019-01-23T19:25:39.093

1Apparently logging out and an in again is sufficient – piec – 2020-02-07T15:10:39.697

20

You can use SharpKeys to map any key to any other key in Windows 7, 8, or 10. It's much easier and cleaner to do than to modify the registry yourself.

Hope this helps.

moeabdol

Posted 2015-08-02T12:36:09.643

Reputation: 381

2Can I use this to switch languages by pressing caps lock ? – thanos.a – 2019-01-05T17:34:09.523

16

I use the following to send CTRL for the CAPS LOCK key, send ALT for the CTRL key, and send CAPS LOCK for the ALT key. CTRL is to the left of "A" where God intended it, ALT is below SHIFT, and the utterly useless CAPS LOCK key is safely tucked away where I have to break my wrist to hit it.

Windows Registry Editor Version 5.00

; The hex data is in five groups of four bytes:
;   00,00,00,00,\    header version (always 00000000)
;   00,00,00,00,\    header flags (always 00000000)
;   04,00,00,00,\    # of entries (3 in this case) plus a NULL terminator line.
;                    Entries are in 2-byte pairs: Key code to send & keyboard key to send it.
;                    Each entry is in LSB, MSB order.
;   1d,00,3a,00,\    Send LEFT CTRL (0x001d) code when user presses the CAPS LOCK key (0x003a) 
;   38,00,1d,00,\    Send LEFT ALT (0x0038) code when user presses the LEFT CTRL key (0x001d) 
;   3a,00,38,00,\    Send CAPS LOCK (0x3A) code when user presses the LEFT ALT key (0x0038) 
;   00,00,00,00      NULL terminator

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,\
                   00,00,00,00,\
                   04,00,00,00,\
                   1d,00,3a,00,\
                   38,00,1d,00,\
                   3a,00,38,00,\
                   00,00,00,00

mnemotronic

Posted 2015-08-02T12:36:09.643

Reputation: 281

4I really appreciate the comments. I always wondered what the codes meant. Very helpful. – zaphodtx – 2018-08-08T22:01:41.300

5

This is the script to swap CTRL and CAPS LOCK keys:

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,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00

ady

Posted 2015-08-02T12:36:09.643

Reputation: 151

4

The inexhaustible sysinternals toolbox also provides a little program just for switching capslock with control -- ctrl2cap.exe.

Ernst

Posted 2015-08-02T12:36:09.643

Reputation: 41

Welcome to Super User. Please read How to Recommend Software then [edit] your answer to include at least the minimum required information (the items in bold). Posts without this information may be subject to deletion. Thanks for contributing.

– I say Reinstate Monica – 2018-12-31T18:06:04.900

3

I used to use AutoHotKey to do this.

I'd have a link in the startup directory to run a very basic ahk script:

Capslock::Ctrl

The thing is, Autohotkey isn't run as Administrator so it won't affect privileged windows, unless you use the task scheduler instead of the startup directory to run the script at login with higher privileges. The second problem is that sometimes, the script hangs when resuming sleep, so you may need to reload it, which is annoying.

AutoHotKey is better suited for more complex tasks, like writing macros.

loxaxs

Posted 2015-08-02T12:36:09.643

Reputation: 159

I tried the autohotkey solution and i do not recommend it. It doesn't work well if you have your autorepeat speed high, delay low. It also doesn't mix well with xkeymacs, which makes emacs keys work almost everywhere in Windows. – Reb.Cabin – 2019-03-30T04:32:44.320

I don't use emacs, open a .ahk file automatically at login, and find this solution to be the most simple and portable by far – Bjorks number one fan – 2019-08-07T10:51:53.637

2

You can use lswitch to remap language input to CapsLock.

Use any key to switch input languages, usage: lswitch [keycode]. Keycode is optional and defaults to context menu key. Another good candidate is a CapsLock key with a keycode of 20.

lswitch 20

Add it to autoload.

Andrew K.

Posted 2015-08-02T12:36:09.643

Reputation: 121

this works, however the caps lock functionality is lost. any idea on how to define the caps lock functionality to shift+caps lock combination? – thanos.a – 2019-01-05T17:51:14.933

2

If, for some reason, you don't want to run third-party tools, it's possible to do this yourself with a bit of C. Thanks to Susam Pal's brilliant answer, I put the snippet below together.

It's practically a key-logger. It listens for key presses, captures them, and constructs keyboard input with the mapping in mind. The below console app need to be running for it to work.

You will need to compile this somehow. I used msys2.org with pacman -S mingw-w64-x86_64-gcc and compiled with /mingw64/bin/gcc nocaps.c -o nocaps.exe.

#include <stdio.h>
#include <windows.h>

HHOOK hook;

#define KEYCODE_CAPSLOCK 20
#define KEYCODE_LCTRL 162

LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
    KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *) lParam;
    INPUT input = {.type = INPUT_KEYBOARD };

    printf("nCode=%d\t wParam=%d\t p->vkCode=%lu \t p->scanCode=%d\t\n", nCode, wParam, p->vkCode, p->scanCode);


    if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
        input.ki.dwFlags = KEYEVENTF_KEYUP;
    }

    if (p->vkCode == KEYCODE_CAPSLOCK && (p->flags & LLKHF_INJECTED) == 0) {
        input.ki.wVk = KEYCODE_LCTRL;
        SendInput(1, &input, sizeof (INPUT));
        return 1;
    } else if (p->vkCode == KEYCODE_LCTRL && (p->flags & LLKHF_INJECTED) == 0) {
        input.ki.wVk = KEYCODE_CAPSLOCK;
        SendInput(1, &input, sizeof (INPUT));
        return 1;
    }

    return CallNextHookEx(hook, nCode, wParam, lParam);
}

int main(int argc, char **argv)
{
    MSG messages;

    hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHook, NULL, 0);
    if (hook == NULL) {
        printf("Error %d\n", GetLastError());
        return 1;
    }

    printf("Mapping CAPSLOCK=>LCTRL and LCTRL=>CAPSLOCK..\n");
    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return 0;
}

kristianlm

Posted 2015-08-02T12:36:09.643

Reputation: 121