Hotkeys

Three months ago, I began using my Logitech G610 keyboard at work to avoid managing KVM hygiene everyday — side-effect of a hot-desking policy. It is a fine, if hefty, full-sized keyboard, and that became a problem. I mean at the end of every work day, I’d unplug to shove it inside a 1’-0”×1’-0” locker, leaving very little usable room for anything else.

Not wanting to buy yet another, I pulled my seldom-used Apple bluetooth wireless keyboard out. This in many ways is worse than its large, corded sibling. For the portability you inherit its handicap of missing keys — some of them critical to be productive; this aside from the prospect of blowing one’s mind with jumbled hotkeys across OSes — Mac at home; Windows at work.

To recover sanity, I looked at ways to remap keys so I could use Mac hotkeys on Windows, and found AutoHotkey promising. As a general scripting tool, however, there is no way around the manual, and it so took me a good few trial and error compiles to get to a set of usable hotkey mappings. I then compiled mackeyboard.ahk script together with a ⌘ key icon to generate mackeyboard.exe file.

It runs just fine in the background capturing all my hotkeys pressed in Mac-style and transforming them into Windows hotkeys on the fly.

Text expansion

Not to be done with hotkeys, it also works great as a text expander, saving me some repetitive typing. Here is an example.

Custom preamble is prepared in a reply email using sender's firstname for salutation when I hit the key combination Alt + x after selecting a message in my Inbox
Custom preamble is prepared in a reply email using sender's firstname for salutation when I hit the key combination Alt + x after selecting a message in my Inbox.

The AutoHotkey code I use to auto-produce the above is as follows.

; In Microsoft Outlook only
#IfWinActive ahk_class rctrl_renwnd32

!x::
ol := COMObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1)
From := ol.SenderName
StringGetPos, pos, From, `,
if errorlevel
{
    StringGetPos, pos, From, %A_Space%
    StringLeft, From, From, pos
}
else
{
    StringTrimLeft, From, From, pos+2
}
StringUpper From, From, T
FirstName := RegExReplace(From, " .*", "")
SendInput, ^+r
Sleep, 100
SendInput, Hi %FirstName%, {Enter 2}Thank you for your email.{Enter 2}
Return

#IfWinActive

The IfWinActive enclosure ensures that this hotkey (Alt + x) is only triggered when Microsoft Outlook is the active window. This is enabled by ahk_class, which for Microsoft Outlook happens to be rctrl_renwnd32. Since I began working on this afresh, I had to figure out the application class for AutoHotkey to work. I have identified a few for some common applications. There are a few nuggets like these in the repository. Do check them out.

Digressing into Mac territory, it’s a lot easier to do this above in Apple Mail with TextExpander app together with a sprinkling of AppleScript and a text expansion trigger.

Custom preamble is prepared in a reply email using sender's firstname for salutation when I hit `;re` text expansion trigger
Custom preamble is prepared in a reply email using sender's firstname for salutation when I hit `;re` text expansion trigger
tell application "Mail"
    set selected to selection
    set msg to item 1 of selected
    set sentBy to (sender of msg)
    "Hi " & word 1 of sentBy & ",\n\nThank you for your email."
end tell