How can I remap a keyboard key?

75

20

One of my laptop's keys has fallen off. Is there any way I can remap another key to serve as that key? I'll 'sacrifice' the other key because I never use it.

Pure.Krome

Posted 2009-09-07T04:23:19.677

Reputation: 1 713

3

This question covers permanently remapping keys. Most answers are based on a registry edit requiring a reboot. For ways to remap keys without a restart, swapping keys with each other, or swapping for specific applications, see this question: Remapping keyboard keys for specific applications

– Lilienthal – 2015-10-21T21:17:08.997

@harrymc the vlaurie.com link is dead (now hosted by ParkLogic) – john v kumpf – 2018-07-13T01:51:18.493

@johnvkumpf: There are heaps of such articles. Most dead links can still be found on the Wayback Machine. For this one see here.

– harrymc – 2018-07-13T07:54:13.600

SharpKeys (free download from authoritative source): https://github.com/randyrants/sharpkeys/releases

– caw – 2020-02-13T19:30:11.120

29Scroll lock: Why are you looking at me? – Colonel Panic – 2013-05-30T23:44:45.663

Answers

43

Here is a good article from Howtogeek about using a utility called SharpKeys:

Map Any Key to Any Key on Windows 10, 8, 7, or Vista

If you are tired of the way certain keys on your system work, such as the Caps Lock key, you can re-map them to function as a different key by using a registry hack. But there should be an easier way, right?

This is where SharpKeys comes into the picture: It’s a small utility that will let you easily map one key to another key easily, or even turn the key off, without having to enter the registry at all.

For instance, I used the key mapping to just turn off my Caps Lock key, since I never use it.

image

You can click the Add button to bring up the Add New Key Mapping dialog, where you can either select the keys to map from the lists, or just click the Type Key button and press the key manually (which I find much more intuitive)

image

Once you are done, click the Write to Registry button and you’ll be told to log off or reboot for the changes to take effect.

image

If you want all the technical details on how the registry keys work, you can read about how to map keys using registry hacks.

Link for reference

William Hilsum

Posted 2009-09-07T04:23:19.677

Reputation: 111 572

Will this allow me to swap the Fn and Ctrl key in Windows on a Macbook Pro Retina running Bootcamp? Thanks. – dotnethaggis – 2014-08-27T13:31:21.163

Do I have to run the app all the time, or is the change permanent? – Colonel Panic – 2015-10-07T16:04:44.550

The HowToGeek registry hack link above is perfect for doing this without software -- but the scancode link in said article is dead. Here's a live (as of today) one: https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx

– Joe – 2015-10-14T18:19:18.003

I am using two different USB keyboards the same time, working multilingual. One of my keyboards has a disturbing layout for INS, END, DEL, ... that I wanted to change. Needing to reboot everytime I change the keyboard is not a solution. Then probably Autohotkey is. Need a simple on-off-switch. Or I just get used to SHIFT + NumKeys... – Kai Noack – 2016-09-29T07:52:38.947

It seems my custom mapping was reset after a Windows update. Did anyone had this issues? – Anton Daneyko – 2016-10-14T12:54:54.497

Seems like this doesnt support remapping to Alt Gr. – mizipzor – 2017-02-06T12:01:35.550

Very easy to use - would be more lovely to be able to toggle the keys (enable/disable it) without deleting anything – Nam G VU – 2011-02-04T05:14:35.383

4For simple remapping this is the way to go, no need to write a full blown autohotkey script. I swear by AHK don't get me wrong, but thats more for keyboard combinations rather than simple remapping. – John T – 2009-09-07T05:58:09.270

13

Using Microsoft Keyboard Layout Creator here without problems. For switching modifier keys I would suggest a registry hack or an application that changes the registry for you, do not use a pure software remap like AutoHotkey as those solutions don't work for every application.

Another solution is to get a replacement key in case you really can't insert the key back in your laptop, have you tried a search for 'broken laptop key'?

Tamara Wijsman

Posted 2009-09-07T04:23:19.677

Reputation: 54 163

For some applications that (presumably) are listening to keydown events it is also necessary to also remap keyboard scan codes. It's a nice solution because it's built into windows and you can use the windows shortcuts. – David Sopko – 2018-10-09T02:40:58.657

The only problem is that it requires .NET Framework 2.0 - if you install it to run the keyboard layout creator, make sure you uninstall it after! – stiv – 2019-11-20T17:35:16.017

2This is th best solution I have found - unlike AutoHotKey and Keytweak, I can modify the characters generated with modifiers, without changing the unmodified behaviour. Now I can get ( and ) without Shift, 9 and 0 are unaffected! :D – James Broadhead – 2011-05-23T09:23:15.003

Well, for my case of converting a qwertz keyboard into a qwerty keyboard this does not work, because ctrl+z stays next to the t. :( – ANeves – 2014-03-01T17:33:11.827

9

You can use Microsoft's Keyboard Layout Creator.
This will even allow you to add extra functionality to your keyboard, such as changing a key into a dead key (e.g. ~), add extra mappings (e.g. altgr+c ->ç), etc.

In order to edit the special keystrokes, like ctrl+FOO, you might need to edit the .klc file manually.
You can find instructions by @Senseful in https://superuser.com/a/172993/157884 :

You need to modify the .klc file manually.

Basically you just modify the VK_ column to match the value in column 1.

So for example if you want to bind L to N, you would create the keyboard as you normally would in KLC. Then you would open the KLC file in a text editor. Find the value L in the VK_ column, and switch it to an N.

For more information, I wrote the complete steps on my blog.

Warning: incomplete support for key bindings in somme applications

However, be warned that some applications might not take those special keystrokes properly.

As an example: with my particular configuration, pressing altgr+a in DotA2's teamchat will erase the text — instead of adding an ã like in other applications.

ANeves

Posted 2009-09-07T04:23:19.677

Reputation: 180

3

I have Genius KB-G235 USB keyboard (HID) and WinXP SP3. Neither of applications in previous answers didnt work for me. (Because working with PS/2 codes or not (fully) with XP).

I tried HotkeyP (freeware) http://petr.lastovicka.sweb.cz/others.html and this works! Just add action for key and its done. (After assign new action isn't default action executed.)

ich

Posted 2009-09-07T04:23:19.677

Reputation: 31

2

http://www.autohotkey.com/ can be a simpler and powerful solution. You can remap keys and create modifiers keys using scripts like

;Use Capslock as a modifier and not as capslock anymore
$*Capslock::
    Gui, 99:+ToolWindow
    Gui, 99:Show, x-1 w1 +NoActivate, Capslock Is Down
    keywait, Capslock
    Gui, 99:Destroy
    return

;Write functions for keys while capslock is beeing hold here
#IfWinExist, Capslock Is Down
    j::Down
    k::Up
    l::Right
    h::Left
    m::AppsKey
    i::Insert
    d::Delete
#IfWinExist

;Use right and left shifts to toggle capslock
RShift & LShift::
    SetCapsLockState, % (State:=!State) ? "On" : "Off"
    return

LShift & RShift::
    SetCapsLockState, % (State:=!State) ? "On" : "Off"
    return

Jp_

Posted 2009-09-07T04:23:19.677

Reputation: 329

But why all of this if something like ScrollLock::LControl is just enough for the remapping? – Yuuza – 2016-04-08T02:26:34.443

Sorry, I really could simplify, but I wanted to show the power of the tool. With this script you don't need to sacrifice keys, you just need to have a modifier key and have a second function for one key. – Jp_ – 2016-04-08T11:43:19.900

2

The easiest way: The Microsoft Keyboard Layout Creator. This is an official Microsoft solution. Functionality is similar like Ukelele for OS X.

Download and instructions: https://www.microsoft.com/en-us/download/details.aspx?id=22339

Adam Szabo

Posted 2009-09-07T04:23:19.677

Reputation: 151

@Luke the link still works for me. The page have a huge surface ad, but below that Microsoft Keyboard Layout Creator 1.4 download is still available. – Adam Szabo – 2018-11-01T14:13:17.737

Page is down near the end of 2019. – James B – 2019-10-30T09:16:37.463

@James B Thanks, updated the link. – Adam Szabo – 2020-02-03T13:34:03.300

2

Keyman Desktop - You can even create your own custom keyboards with Keyman Developer. With keyboards for over 1000 languages, Keyman Desktop lets you type in your language even when Windows doesn’t.

Davidenko

Posted 2009-09-07T04:23:19.677

Reputation: 1 279

1The Keyman software is becoming free after SIL International bought it. This makes it a more interesting choice than before. (Few people would buy software to do just a simple mapping of a key for personal use.) – Jukka K. Korpela – 2017-03-02T18:25:30.493

0

I found one app which can do almost all of them in windows 7 and it works without any issues when your desktop is unlocked. Also it is pretty easy to use.

http://sourceforge.net/projects/hotkeyp/?source=typ_redirect.

Only drawback I found is it will not work when desktop is locked say I come back from sleep and the computer is locked and I have loud music playing. Multimedia keyboards can mute from there itself. But with this app you need to unlock first.

digitally_inspired

Posted 2009-09-07T04:23:19.677

Reputation: 97