AutoHotKey

I noticed that AutoHotKey provides a solution to my keyboard layout problem in Emacs.

Description of Problem

Assume that my physical keyboard is in US layout. Then I add a French(Canadian) layout in Windows and switch to that, because I want to type the French accents more easily. In Emacs, I have bound the undo function to the key C-/. When I want to undo, my muscle memory makes me reach for the key that is no longer / in the French layout... Emacs complains that C-é is not defined (or is not associated to any function). This is very confusing. Is there some way to tie the hotkey to the physical layout of the keyboard? Besides I am pretty sure that I will not bind anything to C-é.

Solution

Install AutoHotKey, make a file with .ahk extension with the following content and run it.

#IfWinActive ahk_class Emacs
$^SC035::Send, ^/

I used the Window Spy that comes with AutoHotKey to find the scan code (which according to the documentation is some code attached to a key on the physical keyboard) of / on my physical US keyboard. It turns out to be SC035. There. The most basic AutoHotKey script applied.

Your Toolbar

A long time ago, Kura introduced me to the tool called Your Toolbar. I use it to facilitate drawing on my Surface tablet. Well, after getting a magic keyboard from Apple, I have largely stopped using it. That tool was essentially an Autohotkey script. Thus behold the power of Autohotkey!

However I think the ahk scripting language (version 1) is terrible. It is concise for doing basic things. Yet it poses a lot of restrictions which makes adding more advanced functionalities tricky, resulting in spaghetti code. It seems that version 2 is in the making and it seems that it is much more to my taste. I am waiting for it to stabilise before delving in.

By the way, I looked into the source code of Your Toolbar and ported the taskbar hiding function to 64-bit AutoHotKey.

See comments in the code for more details.