My Technical Notes

Monday, 18 March 2013

Autohotkey meaning of $ (dollar) symbol

Pressing Control-s to save (the document I was editing) caused me frequently to press Control a (select all) by mistake, therefore the caret would end up at the bottom of the screen. Therefore I wanted a way of disabling Control-a but then mapping CapsLock-a to Control-a. My first solution is as follows:

CapsLock & a::Send ^a

Which is a fair first attempt. What I noticed though was that CapsLock-a was not doing the action of selecting all. What I later realized is that when typing CapsLock-a, Autohotkey was sending Control-a and Control-a was mapped within Autohotkey to do nothing. How do I get out of this trap?

The answer is to use the $ keyword. This is the same as using #UseHook. The following was my second (and correct) solution:

CapsLock & a::Send ^a

The reason why this worked, to quote AutoHotkey's Hotkeys page:

The $ prefix ... prevents the Send command from triggering it.

Therefore, when we press CapsLock-a, the Send command will not trigger the Hotkey ^a but instead will send Control-a to the application.

No comments: