Saturday, July 4, 2020

Remap a Key to Work Around a Broken Keyboard Key on a Windows 10 PC


While you can use Microsoft's PowerToy's Keyboard Manager to remap a key, I advocate using AutoHotKey (AHK) instead. Why? It does the same thing and more. In additional to simulate pressing a broken key with another key or a set of keystrokes, you can for example press a key and have AHK type out a string of text (perhaps your email signature), or your favorite website's url, or even have AHK directly launch your url using a browser.

AHK website. On using AHK to remap key to work around broken keyboard.


In addition to remapping broken keys, you might also want to remap keys so all your laptops have a more consistent keyboard layout. I had a Samsung NC10 and the key locations are quite different from my Lenovo x61. Because of the difference and my constant use of both, I hit the wrong keys a lot. Remapping the keys of one laptop alleviates this problem.

How to set this up


But back to the more pressing problem of replacing a broken key, you will first need to install AHK. You can get AHK on their website at https://www.autohotkey.com. I have been using a very old 1.0.48.3 version (never saw the need to update), and the AHK website has a specific link to download this deprecated 1.0 version. Though I have not tested this with the newer version, I would think the newer version should work just as fine.

After you have installed AHK, write a script to specify the key remapping. One way to use AHK is to write a script, run it, and instruct AHK to constantly monitor your keypresses and act as directed. Here is one of my remap key scripts. To use it, you would save it as a text file (say using notepad) and save it with the .ahk suffix. I remap the end key to function like insert key, and the insert key to function like the end key -- because of the NC10 vs X61 issue I mentioned about. Note the first 3 lines are comments and is not necessary for the script to work. On the fourth line, all it tells AHK to do is if the "end" key is press, send the "insert" key instead.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Remap end and insert key for laptop
    ;; Note it is possible to remap via registry
    ;;   also: http://www.autohotkey.com/docs/misc/Remap.htm
    end::insert
    insert::end
If you want to run the script at Windows startup, you can create a shortcut with the following syntax, and put it in your Startup folder.
"C:\Programs\AutoHotkeyAutoHotkey.exe" "c:\bin\KeysRemap.ahk"
For Windows 10, the startup folder is located at the following location. Remember to replace "userName" with your own username. 
C:\Users\userName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Some suggestions for what keys to use as replacement


There are surprising number of keys that I don't regularly, if ever, use. Some keys to consider: the menu key that usually located on the right side of the space bar (AppsKey), right alt (RAlt), caps lock (CapsLock), scroll lock (ScrollLock), or print screen (PrintScreen). Numpad keys might also work for you if you rarely use them. A more complete list of keys and their names is located here: https://www.autohotkey.com/docs/KeyList.htm

Concluding thought


As further advocation of using AHK, the program has a good community via its forum for support and you stand a good chance of finding help with your particular program and automations and shortcuts. I highly recommend giving it a try.