Home Forum Gallery Movies Downloads
Welcome, Guest. Please login or register.
Links
AutoIt
Simple Macro

AutoIt Version: 3.2.12.1
In this tutorial, I will show you how to create macros for your favorite games !

First, we have to determine what are the actions we want our macro to execute. For the purpose of this tutorial, I will be doing a macro that automatically casts my BO skills for my paladin. So here is how I do it.
  • I hit "W"
  • I hit F6 - Right Click twice
  • I hit F7 - Right Click twice
  • I hit "W"
  • I hit F5 - Right Click twice
  • I hit F2

Now that I have determined all the actions my macro needs to do. We can now start coding.

Code:
Send("W{F6}")
MouseClick("Right")
MouseClick("Right")
Send("{F7}")
MouseClick("Right")
MouseClick("Right")
Send("W{F5}")
MouseClick("Right")
MouseClick("Right")
Send("{F2}")

This basically does exactly what I just said I wanted to do... The only problem is that it does it as soon as I run the program... which is not very convenient. It would be great if we could have a hotkey that runs this piece of code everytime we press it. So this is what we are going to do.

We will need to define the previous piece of code as a function and also add a loop to our program so we can use our macro more than once.

Code:
HotKeySet("{F11}","cast")

While 1
Sleep(100) ; I added a sleep here so our program doesn't use 100% of the CPU.
WEnd


Func cast()
Send("W{F6}")
MouseClick("Right")
        MouseClick("Right")
Send("{F7}")
MouseClick("Right")
        MouseClick("Right")
Send("W{F5}")
MouseClick("Right")
        MouseClick("Right")
Send("{F2}")
EndFunc

If you try the script, it will not work. Why ? Because as with many other games, Diablo II doesn't have enough time to register all the keypresses sent by the script, it's too fast ! So now we need to fine-tune this script.

First I will alter both the length of the brief pause in between sent keystrokes and the length of time a key is held down before being released during a keystroke by using "SendKeyDelay" and "SendKeyDownDelay".

Code:
Opt('SendKeyDelay', 35) ; Default is 5
Opt('SendKeyDownDelay', 35) ; Default is 5

Now I will modify the length a click is held down before being released.

Code:
Opt('MouseClickDownDelay', 20) ;Default is 10

This should do it. Now, it is time to test the script. If you are using SciTE (special AutoIt version) simply press F5, if you are not using SciTE, I strongly recommend you download it here.

After some testing and fine-tuning :

Code:
Opt('SendKeyDelay', 205) ; Default is 5
Opt('SendKeyDownDelay', 195) ; Default is 5
Opt('MouseClickDownDelay', 35) ;Default is 10

HotKeySet("{F11}","cast")

While 1
Sleep(100) ; I put a sleep here so our program doesn't use 100% of the CPU.
WEnd


Func cast()
Send("W")
Send("{F6}")
MouseClick("Right")
MouseClick("Right")
Sleep(100)
Send("{F7}")
MouseClick("Right")
MouseClick("Right")
Sleep(300)
Send("W")
Sleep(200)
Send("{F5}")
MouseClick("Right")
MouseClick("Right")
Sleep(100)
Send("{F2}")
EndFunc

There you go. We now have a working macro ! Only one thing left to do. As you may have noticed, I added a loop in the program, but it is an infinite loop (it will run forever), and this is not what we want. We can solve this by adding a very simple function that will exit the program when we hit a key.

Code:
HotKeySet("{F10}","end")

Func end()
Exit
EndFunc

Macro.au3


Random Image
Registration
 
 
© 2008 D3portal