[TUTORIAL] AutoIT: Automate and scripting

Remis

Well-Known Member
Messages
663
1. WTF is AutoIT?

AutoIT is one of the best script languages for automating s.th. and lot of other stuff.
Very easily to learn.
http://www.autoitscript.com/autoit3/

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!

AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.

Features:

* Easy to learn BASIC-like syntax
* Simulate keystrokes and mouse movements
* Manipulate windows and processes
* Interact with all standard windows controls
* Scripts can be compiled into standalone executables
* Create Graphical User Interfaces (GUIs)
* COM support
* Regular expressions
* Directly call external DLL and Windows API functions
* Scriptable RunAs functions
* Detailed helpfile and large community-based support forums
* Compatible with Windows 95 / 98 / ME / NT4 / 2000 / XP / 2003 / Vista / 2008
* Unicode and x64 support
* Digitally signed for peace of mind
* Works with Windows Vista's User Account Control (UAC)

2. The main part of this post: A simple spammer

You lear how to create a spammer, you can stop spamming pressing "Num8", and start spamming pressing "Num7".
You can even modify this to your own keybinder.

First you need a GUI:
Code:
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Samp", 285, 98, 193, 125)
$Samp_Spammer_ = GUICtrlCreateLabel("Spammer v1", 160, 64, 103, 17)
$Samp_Text = GUICtrlCreateInput("Sampe_Text", 16, 40, 257, 21)
$ffffffffffffffffffff = GUICtrlCreateLabel("7 to activate, 8 to deativate", 16, 8, 232, 17)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

Then we set some hotkeys, for start spam progress and stop it. They start the functions "Start", or "End"
Code:
HotKeySet ( "{Numpad7}" , "Start" ) 
HotKeySet ( "{Numpad8}" , "End" )

A global varibale. It saves whether the programm should spam or not. Its set to 0 after starting the programm
Code:
Global $modus = 0

Then we add the needed functions "Start" and "End" to modify the global variable
Code:
Func Start()
	$modus = 1
	
EndFunc

Func End()
	$modus = 0
	
	EndFunc

Finaly, a loop to spam the text in the label, but only if the global varibale is true
Code:
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $GUI_EVENT_CLOSE
	
			Exit

	EndSwitch
	if $modus = 1 Then
		Send("{F6}")
		Send(GUICtrlRead($samp_text))
		Send("{ENTER}")
		EndIf
WEnd







(I made the GUI with Koda, a GUI designer, you dont need it for scripting, but its easier using it:
http://www.autoitscript.com/forum/index.php?showtopic=32299)

3. Ok, now for short, for all who want to have a summary



1.Create a .txt file, type in the following code.
2.Then rename the file to .au3.
3.Compile it to a .exe file with the "Compile script to exe" application and then its done.
You will find all applications you need in the path where you installed AutoIT (editor, compiler, au3 to exe)!

Code:
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Samp", 285, 98, 193, 125)
$Samp_Spammer_ = GUICtrlCreateLabel("Spammer v1", 160, 64, 103, 17)
$Samp_Text = GUICtrlCreateInput("Sampe_Text", 16, 40, 257, 21)
$ffffffffffffffffffff = GUICtrlCreateLabel("7 to activate, 8 to deativate", 16, 8, 232, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

HotKeySet ( "{Numpad7}" , "Start" ) 
HotKeySet ( "{Numpad8}" , "End" ) 

Global $modus = 0

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $GUI_EVENT_CLOSE
	
			Exit

	EndSwitch
	if $modus = 1 Then
		Send("{F6}") ; open chat box
		Send(GUICtrlRead($samp_text)) ;reading the label
		Send("{ENTER}") ; and send it 
		EndIf
WEnd

Func Start()
	$modus = 1
	
EndFunc

Func End()
	$modus = 0
	
	EndFunc

Mirrors:
Script [Pastebin]
Compiled exe

Post comments, bug pls :)
On enough requests I will post a keybinder tutorial.
 
Re: AutoIT: Automate and scripting

Very nice tutorial, but don't call it a SA-MP Spammer, I don't wanna get banned.. , call it a Spammer, not a specifically one for SA-MP :wink:
 
Re: AutoIT: Automate and scripting

Auch, my brain exploded... i should stop looking at these kinds of things...
 
Re: AutoIT: Automate and scripting

Can't there be made a GTA:SA Machinima tool?
Like automatic CameraZ-X-Y actions, smooth movements, etc.?
 
Re: AutoIT: Automate and scripting

Yeatric said:
Can't there be made a GTA:SA Machinima tool?
Like automatic CameraZ-X-Y actions, smooth movements, etc.?
You Mean something Like SA Camhack?
 
Re: AutoIT: Automate and scripting

GPow69 said:
Auch, my brain exploded... i should stop looking at these kinds of things...
The code is fairly simple, much much simpler than C++ or C!
 
Back
Top Bottom