If you’re using an Italian keyboard or any keyboard that does not have built-in keys for backtick ` and tilde ~ characters and you do some kind of programming or simply write your notes in Markdown everyday like me, you’ll know the struggle of hitting the Alt + 126 ASCII keycode for the tilde and Alt + 96 for the backtick.

Everything is smooth until you need to write a code block in Markdown that needs 6 (six!) backticks in order to be recognized correctly… that means hitting Alt + 96 six times, or 12 key strokes in total.

Even worse, if you’re writing from a laptop keyboard that does not have a numpad, good luck!

It becomes really boring pretty fast, right?

That’s why you absolutely need to create an AutoHotkey script for this!

  • Download and install AutoHotkey or just choco install autohotkey if you use the Chocolatey package manager
  • Go to a folder on your local drive and Right-click -> New -> AutoHotkey script (you could also create a blank .txt file but you would need to set the encoding to UTF-8 with BOM for this script to work correctly, and creating an AutoHotkey script this way does everything automatically)
  • Right-click on the file you just created and click on Edit script
  • Replace the contents with the following black-magic script (I’ll explain later what it does):
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Tilde character with AltGr+ì
<^>!ì::~

; Backtick character with AltGr+'
<^>!'::`
  • Save the file and double-click it to run it
  • The script should now be running in the background (you can check it by finding the little green H icon in the tray bar)
  • Open a notepad and try to press the AltGr + ' or the AltGr + ì key combinations
  • Profit!

I decided to use the AltGr + ' and AltGr + ì key combinations because they don’t do anything useful on my layout, and they are pretty comfy to reach while typing.

So what is that hieroglyphic language <^>!'::`?

The caret symbol ^ represents the Ctrl key, the exclamation mark ! represents the Alt key, and the apostrophe ' represents itself, the :: represent the boundary between the shortcut on the left and what needs to happen on the right, and finally the ` represents the character we want to output.

Windows represents the AltGr key as a combination of Left Ctrl and Right Alt, and the modifiers < and > prefixed to a symbol represent the side of the keyboard to emulate, in this case <^ means Left Ctrl and >! means Right Alt.

Now that you know how it all works and you’ve set it up, you’ll quickly fall in love with it and I’m pretty sure you’ll want this script to run at every startup! To do that you can create a simple scheduled task with the Windows Task Scheduler:

  • In the General tab make sure to select Run only when user is logged on
  • In the Triggers tab make sure to create a trigger that runs At log on
  • In the Actions tab create a new Start a program action, browse to your AutoHotkey.exe (by default it’s located at C:\Program Files\AutoHotkey\AutoHotkey.exe) and paste the full path of your script as a an argument (to grab the full path just right-click on the script while you’re pressing the Shift key, then select Copy as path)
  • If you’re working on a laptop, deselect the Start the task only if the computer is on AC power flag from the Conditions tab

~~~ Now go and enjoy writing ` backtick ` and ~ tilde ~ characters all over your documents! ~~~