Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Map Caps Lock to Escape or any key to any key

License

NotificationsYou must be signed in to change notification settings

susam/uncap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Map Caps Lock key to Escape key, or any to any key, on Windows systems.

DownloadMIT LicenseTwitter

Apart from documenting how Uncap works on Windows, this README containsdetailed documentation about how to remap keys on Linux and Mac as well.

Contents

Features

The following list briefly describes some of the features of Uncap.

  1. Map Caps Lock key to Escape key on a new Windows system with almostno effort. Just download and double-click. This is the primaryreason why Uncap was written. This tool was written for users ofvi/Vim editor who like to map their Caps Lock key to Escape key forconvenience.
  2. Map any key to any key, multiple keys to other keys, or disablekeys using command line arguments. No additional file or script isrequired.
  3. Enable, disable or modify key mappings without having to reboot theWindows system.
  4. Disable key mappings easily by stopping Uncap.
  5. It is a single-file executable. It is very lightweight. Theexecutable is only about 100 KB in size. It occupies less than 1 MBof memory and negligible CPU while running.

There are several other methods and tools available on Windows to mapone key to another. But none of them seem to have all five featuresenumerated above. For example, editingScancodeMap registry value requires theWindows system to be rebooted after every change. On the other handAutoHotkey requires an additional script file tobe written. Therefore, Uncap was written to support all five featuresdescribed above.

Get Started

Uncap is a single-file executable:uncap.exe.

The simplest way to run it is to download it and double-click it. Nooutput window is displayed. It runs in background. Once it is running,whenever Caps Lock key is pressed, it is translated to the Escape key byUncap.

Custom Mapping

It is possible to override the default mapping of Caps Lock key toEscape key by specifying a custom mapping, however to do so, Uncap mustbe run with arguments either from Command Prompt or from Windows Rundialog box. The following steps show how uncap.exe may be used to mapCaps Lock key to Left Control key.

  1. Copyuncap.exe to a directory specified in the WindowsPATHvariable.C:\Windows is a very convenient location to copy thisfile to.

  2. Launch Windows Run dialog box by pressingWindows Logo Key +R.

  3. Enter the following command.

    uncap 0x14:0xa2
  4. Press OK button. This would launch Uncap. No output window would bedisplayed. Uncap would run in background. Whenever Caps Lock key ispressed now, Uncap would translate it to Left Control key.

  5. To terminate Uncap, run the following command.

    uncap -k

In the above steps, Caps Lock key is mapped to Left Control key byspecifying0x14:0xa2 as an argument to Uncap. The virtual-key code ofCaps Lock is0x14 and the virtual-key code of Control key is0xa2.Therefore, the argument0x14:0xa2 maps Caps Lock key to Control key.

The list of virtual-key codes for every key can be found athttps://msdn.microsoft.com/library/windows/desktop/dd375731.aspx.

Usage

When Uncap is run without any arguments, it maps Caps Lock key to Escapekey. It may be run with arguments to map Caps Lock key to any key, anykey to any key, or disable any key.

Each argument is a colon separated pair of virtual-key codes fromhttps://msdn.microsoft.com/library/windows/desktop/dd375731.aspx.

The virtual-key code may be specified either as hexadecimal integer asmentioned in the above URL or its equivalent decimal notation. Thesedetails are illustrated in the list of examples below.

  1. Map Caps Lock key to Escape key.

    uncap
  2. Swap Caps Lock key with Escape key.

    uncap 0x1b:0x14

    Caps Lock key is already mapped to Escape key by default. The abovecommand maps Escape key to Caps Lock key, thus effectively swappingboth keys.

  3. The hexadecimal integer is case-insensitive, so the followingcommand is equivalent to the previous command.

    uncap 0x1B:0x14
  4. The virtual-key codes may be specified in decimal notation, so thefollowing command is equivalent to the previous command.

    uncap 27:20
  5. Map Caps Lock key to Left Control key.

    uncap 0x14:0xa2
  6. Swap Caps Lock key and Left Control key.

    uncap 0x14:0xa2 0xa2:0x14

    This example shows that it is possible to specify more than oneargument to map multiple keys to other keys.

  7. Here is another example that maps multiple keys to other keys. Thefollowing command maps Caps Lock key to Left Control key, LeftControl key to Escape key and Escape key to Caps Lock key.

    uncap 0x14:0xa2 0xa2:0x1b 0x1b:0x14
  8. If a key is mapped to itself, then no mapping occurs for it. Thismay be used to override default behaviour of mapping Caps Lock keyto Escape key and leave it unmapped while mapping another key tosome key. Here is an example that unmaps Caps Lock key and maps F1key to escape key.

    uncap 0x14:0x14 0x70:0x1b

    When a key is mapped to another key, and that key is pressed, Uncaptranslates it to the key it is mapped to by synthesizing a newkeystroke and injecting it into the system. But when a key ismapped to itself, and that key is pressed, it is ignored, thus notranslation or synthesis of a new keystroke occurs.

  9. If a key is mapped to 0, then the key is disabled. Here is anexample that disables Caps Lock key completely.

    uncap 0x14:0
  10. Uncap runs without displaying a console by default. To terminateanother instance of Uncap that may be running, use the-k or--kill option.

    uncap -k

    The above command kills all other instances of Uncap that arerunning with or without a console.

  11. To run Uncap with a console, use the-c or--console option.

    uncap -c

    When Uncap is running in a console like this, it may be terminatedby pressingCtrl +C.

  12. To run Uncap in debug mode, use the-d or--debug option.

    uncap -d

    The debug output contains one line of output with details aboutevery press of a key or release of a key.

  13. To log the keystroke details to a file, use the-f or--fileoption.

    uncap -f C:\keys.txt

    With this option alone, Uncap runs in background and logs thekeystroke details to the specified file. This option may becombined with-c or-d to run Uncap in a console or printdebug output on the console, respectively.

  14. See the complete usage details along with options supported.

    uncap -h

Known Issue with Microsoft Edge on Windows 10

When Uncap is downloaded using the Microsoft Edge web browser on Windows10, it sometimes fails to map keys.

The following measures have found to beunsuccessful in resolving theissue:

  • Right clickinguncap.exe, then selectingProperties, thenselectingUnblock, and then clickingOK does not resolve theissue.

  • Right clickinguncap.exe, then selectingProperties, then goingtoSecurity tab, then clickingEdit, and then removing thefollowing two accounts does not resolve the issue:

    Unknown Account(S-1-15-2-3624051433-2125758914-1423191267-1740899205-1073925389-3782572162-737981194)Unknown Account(S-1-15-3-3624051433-2125758914-1423191267-1740899205-1073925389-3782572162-737981194)

    These accounts are added automatically to files downloaded withMicrosoft Edge.

The following workarounds have been found to resolve the issuesuccessfully:

  • Copyuncap.exe to a new file in the same directory. The new filewhen run remaps keys successfully. Finally, delete the downloadeduncap.exe, then rename the new file touncap.exe, and use itnormally.

  • Copyuncap.exe to some other directory. The new copied file whenrun remaps keys successfully.

This issue was observed with Microsoft Edge Microsoft Edge 44.17763.1.0on Windows 10 Pro.

Alternatives

There are other tools and methods available to map one key to another onWindows, Linux and Mac. This section describes a few such tools and methods.

Windows: Scancode Map registry value

One way to map a key to another key in Windows without using anyadditional software is by editing the registry to add a value called"Scancode Map" in "HKLM\SYSTEM\CurrentControlSet\Control\KeyboardLayout" registry key.

For example, to map Caps Lock key to Escape key, create a registrationentries file, i.e. a file with reg as its extension, say uncap.reg, withthe following content.

REGEDIT4[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

Then save the file. Then double-click this file to add it to Windowsregistry. Then reboot the Windows system. After rebooting, whenever CapsLock key is pressed, it would function like Escape key.

The same registry value may be added by running the following command inCommand Prompt.

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /t REG_BINARY /d 00000000000000000200000001003a0000000000

The hexadecimal code in the registry value is the scan code map. Theformat of the scan code map is described in detail athttps://msdn.microsoft.com/library/windows/hardware/jj128267.aspx#scan_code_mapper_for_keyboards.

The following command may be used to view this registry value.

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map"

The following command may be used to remove this registry value.

reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map"

While this method has an advantage that it requires no additionalsoftware, a disadvantage of this method is that it requires the systemto be rebooted after every change in the registry.

There is a tool calledSharpKeys that comes with graphical userinterface to manage this registry value. However a reboot is stillrequired after every change made with SharpKeys.

Windows: AutoHotkey

There is a fairly sophisticated scripting language for Windows calledAutoHotkey that can be used to map one key to another, among manyother things.

It is quite simple to map one key to another using AutoHotkey. Forexample, after installing AutoHotkey, to map Caps Lock key to Escapekey, create an AutoHotkey script, i.e. a file with ahk as its extension,say uncap.ahk, with the following content.

CapsLock::Esc

Then save the file. Then double-click this file to run AutoHotkey withthis script. Once this is done, whenever Caps Lock key is pressed, it istranslated to Escape key. An AutoHotkey icon appears in the notificationarea (system tray). To stop it, right click on the icon and select'Exit'.

This method has an advantage that it does not require the system to berebooted. However, AutoHotkey is a scripting language that can be usedto do a number of other things such as defining hotkeys (shortcut keys),hotstrings (auto-replace), macros (scripted actions), etc. This may feelakin to killing a fly with a sledgehammer if one just wants to map a keyto another key.

Linux: setxkbmap

On Linux, thesetxkbmap command may be used to map one key to anotherkey in the X Window System. For example, the following command maps CapsLock key to Escape key.

setxkbmap -option caps:escape

The list of options along with a short description for each can be foundat /usr/share/X11/xkb/rules in a .lst file with the same name as thecurrent XKB rule. The current XKB rule as well as the current mappingoptions can be found in the output of this command.

setxkbmap -query

For example, if 'evdev' is displayed as the current rules, then see/usr/share/X11/xkb/rules/evdev.lst for the list of available optionsalong with a short description for each option.

In the output of the above command, the line that begins with 'rules:'in the output of the above command shows the current XKB rules. The keymapping option is displayed in the line that begins with 'option:' inthe output of the above command. If there is no such line, then no keymapping option is set.

The following command removes any key mapping option.

setxkbmap -option

Linux: xmodmap

On Linux, there is another command calledxmodmap that may be used tomap one key to another in the X Window System. However this command isnow considered obsolescent. It is also a little clumsy to use,especially while removing a key mapping. Thesetxkbmap commanddescribed in the previous section is the preferred way of mapping keysin the X Window System. However, this section describes how to usexmodmap to map one key to another because this method is still in usealthough its use is gradually fading away. As an example, this sectiondescribes how to map Caps Lock key to Escape key.

Before performing the key mapping, one needs to find the key code ofCaps Lock key in the X Window System. This is useful while reverting thekey mapping. Here is the command to get the key code for Caps Lock key.

xmodmap -pke | grep Caps_Lock

For PC keyboards, the key code is usually66.

The following command maps Caps Lock key to Escape key.

xmodmap -e "remove Lock = Caps_Lock" -e "keysym Caps_Lock = Escape"

Here is another command that also maps Caps Lock key to Escape keyif the key code for Caps Lock is 66. This command makes use ofkeycodeinstead ofkeysym.

xmodmap -e "remove Lock = Caps_Lock" -e "keycode 66 = Escape"

The following two commands display the current details.

xmodmap -pm -pke

The following command undoes the mapping.

xmodmap -e "keycode 66 = Caps_Lock" -e "add Lock = Caps_Lock"

Note thatkeycode is used in the above command. Ifkeysym Escape = Caps_Lock is used instead in the above command, then along withreverting the Caps Lock key to function like Caps Lock, it would alsochange the behaviour of the Escape key to function like Caps Lock. Usingkeycode 66 = Caps_Lock ensures that only the behaviour of Caps Lockkey only is restored.

Linux: loadkeys

On Linux, theloadKeys command may be used to map one key to anotherin console. This section describes how to map Caps Lock key to Escapekey. All commands in this section must be run as root or superuser.

Before performing the key mapping, one needs to find the key code ofCaps Lock key in the console. This is also going to be useful whilereverting the key mapping.

Here is a quick way to find the key code of Caps Lock key in console.

dumpkeys | grep -E "CtrlL_Lock|Caps_Lock"

In this section, we assume that the key code for Caps Lock key is58and it is mapped toCaps_Lock key, which is indeed true on mostsystems. On Debian based systems, the key code58 may be mapped toCtrlL_Lock to work around Debian bug514464 and kernel bug7746.

The following command maps Caps Lock key to Escape key.

(dumpkeys | grep keymaps; echo keycode 58 = Escape) | loadkeys

The following command undoes the mapping.

(dumpkeys | grep keymaps; echo keycode 58 = Caps_Lock) | loadkeys

Mac: System Preferences

Since macOS Sierra Version 10.12.1, it is easy to map Caps Lock to Escape viaSystem Preferences. Perform the following steps to do so.

  1. Go to the Apple menu >System Preferences >Keyboard.
  2. ClickModifier Keys.
  3. SetCaps Lock Key toEscape.
  4. ClickOK.

Mac: Seil

In OS X, the mapping options available viaSystem Preferences are verylimited. For example, it does not allow Caps Lock to be mapped to Escape.Therefore in general, it becomes necessary to install additional software tomap keys in OS X.

A popular tool for mapping one key to another on OS X isSeil. Here is anarticle by my beautiful girlfriend and wife that describes how to map Caps Lockto Escape on OS X using Seil:http://sunainapai.in/blog/map-caps-lock-to-escape-on-mac-os-x/.

Resources

Here is a list of useful links about this project.

License

This is free and open source software. You can use, copy, modify,merge, publish, distribute, sublicense, and/or sell copies of it,under the terms of the MIT License. SeeLICENSE.md for details.

This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,express or implied. SeeLICENSE.md for details.

Support

To report bugs, suggest improvements, or ask questions, please visithttps://github.com/susam/uncap/issues.


[8]ページ先頭

©2009-2025 Movatter.jp