How to remap hotkeys with AutoHotkey

Posted by bL4cK_m0p on Monday, June 1, 2009

People have asked how to remap their hotkeys. And since it's really easy, here's how you do it. Of course you can remap all sorts of hotkeys (and do a lot of other stuff too) but we wont go too in depth on that subject. Read the whole guide before you start to type a single line of code, good luck!

AutoHotkey is a free, open-source utility for Windows. With it, you can:
  • Automate almost anything by sending keystrokes and mouse clicks. You can write a mouse or keyboard macro by hand or use the macro recorder.
  • Create hotkeys for keyboard, joystick, and mouse. Virtually any key, button, or combination can become a hotkey.
  • Expand abbreviations as you type them. For example, typing "btw" can automatically produce "by the way".
  • Create custom data-entry forms, user interfaces, and menu bars.
  • Remap keys and buttons on your keyboard, joystick, and mouse.
  • Respond to signals from hand-held remote controls via the WinLIRC client script.
  • Convert any script into an EXE file that can be run on computers that don't have AutoHotkey installed.
So before you do anything, follow these links below, download and install.

Follow these links:
AutoHotkey 1.0.48.05 installer
AutoHotkey 1.0.48.05 zip

Now let's make our very first script:

1. Right click on your desktop (or where you want the script to be) then choose "New" --> "AutoHotkey script"
2. You will now see a icon popping up, this is your script. Give it a name, e.g. "test".
3. Now right click the script-icon you just created and choose "Edit script". Now a notepad window will popup that has a bunch of text there. You can leave the text there or remove it, it doesn't make much of a difference.

Now when you save this file it will be named "something.ahk". That it ends with ".ahk means that it's a autohotkey script. To run it, simply duble click on it (although, nothing will happen, yet).

When you've ran it a tray icon will appear in the lower right corner. To exit the script, right click the tray icon and select "exit"

Ok so lets start with the actual programming. First lets try this, open your script and at a blank line type:

^space::Run www.dota-allstars.com

Then save and run the script. Now you will see that a small tray icon appears in the right down corner of your screen. Then press ctrl and space. So, what have you just done? "^" stands for the ctrl modifier key. "space" stands for.... you guessed it, the space key! "::" is what tells the program that this is the hotkey, and whatever comes after that is what is to be done when it's pressed. In this case, it runs the url "www.dota-allstars.com" in your default browser.

Let's try something else. Type this on 2 blank rows:

q::Send {enter}hello world!!1{sleep 700}{backspace}
w::space

This is two different ways of remapping hotkeys. The above one uses send, while the one below remaps the key directly. In the one that uses send you see that you have to put brackets ("{}") around key names while you don't have to do that when remapping them directly. Try pressing q and w to see what happens (preferably in a text box).

You can also do like this:

q::
Send {enter}hello world!!1
sleep 700
Send {backspace}
sleep 1500
Msgbox Hello
Return


You can put the things you want to happen below the hotkey, and then end it with a "return". You have to use this format when making more advanced macros, that take more than one line of code. The send command can do a lot, but not everything.

One last. Try this:

enter::tooltip DOWN
enter up::tooltip UP

space::SoundBeep
space up::Msgbox BEEEEEP!

As you see I have a something happen when i press the button, and something else happen when I release it.

Getting the hang of it?

This following piece of code is to show how to make comments in AHK:
After some experimenting I've noticed that this forum (sometimes) removes spaces in front of ";". So my example may not work if you copy/paste. You will need to add a space infront of the ";" (no quotes) or it wont be a comment.



#persistent;this will prevent to script from shutting down when it's done
msgbox This is a message box, it will show
sleep 1000
msgbox This is a message box too;<- Add a space.. This wont show. It's a comment!
sleep 1000
/*
msgbox this wont show since it's a comment
msgbox neither will this one
*/
msgbox this will show though
/*
one last comment....
*/


Here we're going to put some examples of what you can do.

*XButton1::Send, {F1}^8{Numpad7}
*XButton1 up::Send {click}8

*XButton2::Send, {F1}^8{Numpad8}
*XButton2 up::Send {click}8


 This is the one I use at the moment. XButton1 and 2 are special buttons that I have on my mouse (logitech mx518 ).


#ifWinActive, Warcraft III


;;Mouse Wheel to Item Slots
*MButton::Send {F1}{Numpad8}{LButton}8
*WheelUp::Send {F1}{Numpad7}{LButton}8
*WheelDown::Send {F1}{Numpad4}{LButton}8

Credit to "Vassily" for this one (but I modified it some). This one has two really good thing you should remember in it. First "#ifWinActive, Warcraft III", this makes the hotkeys work only in warcraft III. Second the "*" in front of the hotkeys. A * is a wild card, that means that it's anything. If you dont put that one there. The hotkey wont work if your holding e.g. alt. Because if you hold alt and press a key, autohotkey interprets that as "alt+key" instead of just "key".

$y::Send, {Numpad7}
$x::Send, {Numpad8}
$c::Send, {Numpad4}
$v::Send, {Numpad5}

*Enter::
Hotkey, $y, Toggle
Hotkey, $x, Toggle
Hotkey, $c, Toggle
Hotkey, $v, Toggle

GetKeyState, state, Shift
if state = D
Send, +{Enter}
else
Send, {Enter}
return

This is an example how you can toggle keys on and off by using the hotkey command. This is useful when you want to use a letter as a hotkey, because, you still want to be able to type, don't you? So when you press enter it toggles the hotkeys on or of, depending if they where on or off before. Then it checks if you're holding shift, and if you do it sends "alt+enter", if you're not it only sends "enter".
By the way, the $ sign prevents a hotkey to be launched by artificial input. It's not really necessary in this example though.

!c::
send c
sleep 1000
send {numpad2}+{click}
return

This is an example how you can use small macros to preform combos. In this example it's Sand King's "Epicenter + blink dagger"-combo. When you press alt+c it first sends a "c" key and sand king starts channeling epicenter. Then it waits 1000 milliseconds (one second), then it presses numpad2 to use the dagger (assuming it's in the right down slot), then finally it presses "SHIFT+click". The shift modifier is used to queue commands. So when he's done channeling, he will instantaneously use dagger and no "waves" will be wasted. (the sleep time maybe needs some tweaking)

This can of course be used for other "combos" such as "death ward + lothars", "decrepify + dagon", etcetera.

Follow these links:
AutoHotkey 1.0.48.05 installer
AutoHotkey 1.0.48.05 zip

Click like button.

Share to your friends :

{ 0 comments...Please Leave Your Comment }

Post a Comment