Autohotkey Macros Tutorial

Discussion in 'Tutorials' started by nasif, Feb 15, 2015.

  1. nasif

    nasif Illuminati level 34

    Messages:
    147
    Likes Received:
    144
    Trophy Points:
    43
    [​IMG]

    Ever wondered if you could just press a button instead of typing the obnoxiously long commands such as /mycar load infernus? Well wonder no more because AutoHotkey is here! Actually it's not here, it's on another site.

    What is it?
    Basically, it's a macro program. It sends things when you press things. For example: you press Ctrl + 1 and the program sends a //flint command.
    From autohotkey.com: "
    Fast scriptable desktop automation with hotkeys"

    How do I get it?
    Go to http://www.autohotkey.com/ and press Download AutoHotkey.

    How do I use it?
    Open up AutoHotkey and it'll create an AutoHotkey.ahk file for you. In that AutoHotkey.ahk file, you create all your scripts. So open that file up too (right click the AutoHotkey taskbar icon and press Edit This Script.) Don't worry, you don't need a programming software to edit it. Notepad will do.
    [​IMG]
    After you've opened the file up you'll see all sorts of stuff AutoHotkey has written there. You can choose to create a new script or use the one provided; doesn't really matter. Delete all the stuff in the AutoHotkey.ahk file and get ready to rumble!
    But first, get acquainted with the basic modifiers such as ctrl, alt and shift here http://www.autohotkey.com/docs/Hotkeys.htm
    Also read the list of keys here http://www.autohotkey.com/docs/KeyList.htm

    So. You've set everything up and know the basic modifiers. Now you need to decide which keys will do what. In this example, I'm gonna set Ctrl + 1 to send a /mycar load infernus command.
    From the previous link you find that ^ is Ctrl. So we're gonna use that.
    Code:
    ^1
    Now we need to add :: after 1, which indicates what Ctrl 1 will send or change to.
    Code:
    ^1::
    So far so good. Now comes the mycar load part. How are we going to do that? Well, we can use a "Send T/mycar load infernus" command but that might interfere if we have chat already open or something. So we'll use F6 (which opens chat if you didn't know). But wait! Send is a slow command. You can see the typing if you use Send. So we're gonna use SendInput which is faster. Also don't forget to add {return} at the end which is Enter.
    Code:
    ^1:: SendInput {F6}/mycar load infernus{return}
    And finally add a return to the next line which will tell the script to stop running after typing those things.
    Code:
    ^1:: SendInput {F6}/mycar load infernus{return}
    return
    Save the file (Ctrl S) and reload the script by clicking on the taskbar icon and pressing Reload This Script. Try it out in-game.

    And you're done. You've made your first macro. There are a few things to remember though so I'll post them below.

    Things to remember/Tips
    1. This particular example script will run on every program. Yes, press Ctrl 1 here and it'll send the commands. To counter this, add #IfWinActive GTA:SA:MP to the top of your script so it looks like this:
    Code:
    #IfWinActive GTA:SA:MP 
    ^1:: SendInput {F6}/mycar load infernus{return}
    return
    This will make the code run only when SA:MP is running and is the active window. Neat huh?

    2. You can remap your keyboard's extra function keys. Mine has four on each side. You need to find out what keys they are to be able to use them. And there is even a script which helps you determine what keys you're pressing. Read this for more info: http://superuser.com/questions/31265/autohotkey-how-to-assign-a-command-to-the-calc-key

    3. There are hundreds of AutoHotkey commands and hundreds of things it can do. From clicking on a particular part of the screen to making a Graphical UI; it can do all sorts of stuff. Read the official documentation if you want to learn more about AutoHotkey.

    Hope I helped. If you have any suggestions about any part of the topic feel free to send me a message.
     
    Lonewolf, Brada, Paveys and 3 others like this.
  2. Brada

    Brada shrek is lof shrek is lyf

    Messages:
    12
    Likes Received:
    4
    Trophy Points:
    3
    Gender:
    Male
    Location:
    Nepal. Died by earthquake sorry
    Great tutorial. Thank you.
     
  3. Lonewolf

    Lonewolf Player

    Messages:
    36
    Likes Received:
    18
    Trophy Points:
    8
    Gender:
    Male
    Location:
    Saturn
    Bump But thanks
     

Share This Page