Remapping backtick (`) and tilde (~) keyboard shortcuts on Windows

Marco Lancellotti
4 min readNov 16, 2020

--

The problem

If you are a developer and work with Windows, it is very likely that at somepoint in time, you faced with an annoying little issue: typing a backtick and/or a tide in your code.

Maybe you use the new ES6 syntax and needed the backtick to interpolate your variables inside a string. Or maybe, you were trying to set up a CSS sibling selector.

In any case, typing these characters on Windows is quite uncomfortable. If you are lucky enough to have the numberpad on your pc, then you could use the default shortcuts provided by windows… if you can remember them!

The native backtick shortcut on Windows is Alt + 96 , whereas the native shortcut for the tilde is Alt + 126 .

The important point is that the numbers for these shortcuts must be typed on the number pad and, alas, not all computers (especially the small laptops) have the number pad on their keyboard, making it impossible to use them, forcing users to find the desirred characters somewhere on the internet or in other parts of code and copy/paste them, a very annoying procedure.

The solution

Have you ever heard of AutoHotKey?

AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts.

Well, this little program will save your life! You can download it free from its official website, and by doing so, you will be able to write and run some code, to remap all of your keyboard shortcuts.

Let’s see how ca we settle our tilde and backtick comfortable shortcuts thanks to AutoHotKey!

Installation

As stated above, we can install it from https://www.autohotkey.com/. We just need the Standard Installation. Once the wixard ends the installation, there’s no need to run the program.

Create a .ahk file

The main step is to write the script to bind our desired key combinations to print both ~and ' characters.

What I want to acheive is the following shortcuts:

  • AltGr + - prints ~
  • AltGr + ' prints `

If you want to use different key combinations, please refer to the AutoHotKey docs

Let’s start by creating a startup.ahk file on your desktop. You can edit it with your code editor or with the default Windows Notepad. Now, type this:

#Requires AutoHotkey v2.0

<^>!vkDD::Send "~"
<^>!'::Send "``"

Let’s have a look at the script:

There are 2 lines of code, the first for the tilde and the second for the backtick. The first part of each block represents the key combinations in AutoHotKey language:

So in the first line the “<^>!” represents the AltGr key, vkDDrepresents the - key, while the :: represent the end of the key combination. In the second block, the vkDD is substituted by the ' as we decided to use AltGr + ' for the backtick shortcut.

The second part represents what we want the shortcut to return. In the first line we used Send "~" (yes, you will have to copy paste the tilde for now); in the second we must use Send and include two backtick ("``")because the backtick is a reserved character in AutoHotKey, so we need to escape it.

Now, save the file, close it and double click on it. Now our shortcuts will magically work in every program on the PC! This means not only your into your favourite code editor but also in the web browser, on Microsoft Word, in the e-mails and so on… at least untill we shut down the pc! :/

Automatically execute the script at PC startup

Although it is possible to put the file on the desktop and double click on it everytime we turn on the computer, there is a much better way to make our shortcut automatically available at all time.

All you need to do is moving this startup.ahk file, inside this folder:

C:\Users\YOUR_USER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Remember to replace YOUR_USER above with your user name. Also note that the AppData is a hidden folder, so if you don’t see it inside your user’s folder be sure to set the hidden folders as visible.

The Startup folder is a special folder whose files will be executed when we access Windows. Moving our file inside there, will ensure our script to be ran behind the scene every time we turn on the computer!

LEGACY

This is the old code for AutoHotKey Version 1 on Windows 10:

# AutoHotKey v.1.0
<^>!-::
Send ~
Return

<^>!'::
SendRaw ```
Return

--

--

Marco Lancellotti
Marco Lancellotti

Written by Marco Lancellotti

Passionate Coder. Currently Coding Teacher at Boolean Careers

Responses (1)