AutoHotkey

From Deskthority wiki
Jump to: navigation, search
AutoHotkey logo.png
Development status Active
Operating system Microsoft Windows
Type Utility software
License GNU General Public License 2
Website www.autohotkey.com

AutoHotkey is a keyboard remapping and macro language utility for Microsoft Windows. AutoHotkey's syntax spans all the way from trivial declarative mappings up to fully-fledged procedural, graphical software development with the ability to make Windows API calls.

Key remapping

The following script performs the much-desired ability to swap the caps lock key and control key:

Capslock::Ctrl
LCtrl::Capslock

Caps lock becomes a control key, and the left control key is now caps lock. Right control remains unaffected.

Extended character entry

AutoHotkey_L in particular is useful for permitting the entry of any Unicode character at the keyboard (in Unicode-aware applications) from simple keyboard shortcuts. For example, the following AutoHotkey script binds ctrl+alt+N to right arrow ("→", U+2192) and ctrl+alt+M to a true minus sign ("−", U+2212):

^!N::SendInput {U+2192} ; ctrl+alt+N = right arrow
^!M::SendInput {U+2212} ; ctrl+alt+M = minus

While this sort of character entry has been available on the Macintosh for decades, AutoHotkey_L extends this concept out to the full 32-bit Unicode repertoire.

Operator's guide

The most advantageous thing about AutoHotkey is its portability. A script compiled into an .exe stands far higher chance of being allowed to run on corporate/guest computers than would a custom MSKLC-layout-installation, for example.

A second advantage is that you can customise how any key or key-combination works.

For example:

You can turn C into a P, but keep the Ctrl+C command working as normal!

When learning to script AutoHotkey, make a habit of always checking the documentation on the AutoHotkey website. It's all there, in one form or another.

Reliability

AutoHotkey has a somewhat poor reputation concerning its reliability, but this is not as much of an issue lately if at all.

All input events used to be generated with the commands SendEvent and SendPlay, with their respective advantages and disadvantages. The newer command SendInput is much more reliable, is not a hog on the system and has no chance of being interrupted by other system events.

Starting out with AutoHotkey: The basics

Specify SendMode Input at the top of the script if it isn't there (it's there by default in all new scripts). That way the Send command translates into SendInput, which is well desired for performance and reliability. In AutoHotkey_L this is default and does not need specifying. [unconfirmed]

A basic remap in AutoHotkey script is done with this shorthand:

a::o

which makes pressing "a" send the "o" event to the system. (Pressing "o" will still send "o" unless you remap that key too). All modifier states are remapped along with this: for example, Ctrl-A will appear as Ctrl-O to the computer.

Remember that even as you remap, AutoHotkey knows which keys you really mean: always type the key's original QWERTY position.

Remapping several times

DISCLAIMER: The author who wrote this is rusty. Someone confirm it's correct.

Remember that if you remap one key several times, the script is sensitive to the order in which you place them. The higher-up line has greater priority than the lines below. For example:

+[::Send +[
[::(

This turns bracket " [ " into parenthesis " ( ", but keeps the gull-wings sign " { " just where it was.

Here you also see the " + " prefix being used. It specifies that Shift needs to be pressed for the hotkey to trigger. This is not always necessary: you can just type A instead of +a in most cases. Some characters are used in AutoHotkey syntax, like the gull-wings, and can therefore not be used in this context.

" + " specifies Shift, " ^ " specifies Control, " ! " specifies Alt.

" ^>! " or " <^>! " specify AltGr for those that have it, but it can be tricky to get it to work in all situations. Recommend switching to US layout and making RAlt (" >! ") your 'inofficial' AltGr. That is not to say it's not possible to make it work flawlessly, but you need to be a skilled AutoHotkey scripter to do so.

Making hotkeys act as they do on QWERTY

Some people complain that common hotkeys, such as Ctrl-C, get relocated to uncomfy places when learning a different layout. This issue is easy to remedy if you use AutoHotkey:

^z::Send ^z 
^x::Send ^x 
^c::Send ^c 
^v::Send ^v

This way your cut, copy, paste functions are in the same places as before, even if the letters they'll print out are different.

If you have remapped your keyboard with other media than AutoHotkey, change the left side of the "::" to match whatever keys are in those positions on your remapped layout.