Auto IT

Topics on common programming languages
Post Reply
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Auto IT

Post by Rksk » Tue Jan 26, 2010 4:58 pm

There is a very easy and useful scripting language, named AUTO IT.
It can be downloaded from www.autoitscript.com .

i will can help you to be a autoit programmer.
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

What we can do with Auto IT ?

Post by Rksk » Sat Mar 27, 2010 3:24 pm

There is an example to tell you "What we can do with AUTOIT?"

download this zip and extract this 2 files to a directory.
then run it with AUTOIT3 < http://www.autoitscript.com >
*you must set your screen resolution to 1024*768 or higher to run this correctly.

it will run MSpaint and draw a srilankan flag
with automated mouse movements and clicks.
But you can't modify this code because it is obfucated due to it is secret script.

There is the start of code.
you will can learn using it.


Code: Select all


	ProcessClose("mspaint.exe")
	
		Opt("WinWaitDelay", 15)
		Opt("WinTitleMatchMode", 4)
		Opt("WinDetectHiddenText", 1)
		Opt("MouseCoordMode", 0)
		Opt("GUICloseOnESC", 1)
		RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint")
		Sleep(100)
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPHeight", "REG_DWORD", "600")
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPWidth", "REG_DWORD", "800")
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Text", "TypeFaceName", "REG_SZ", "System")
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Text", "PointSize", "REG_DWORD", "14")
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\General-Summary", "ScreenCX", "REG_DWORD", "400")
		RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\General-Summary", "ScreenCY", "REG_DWORD", "300")
		Sleep(100)

		Run("mspaint.exe")

		Opt("WinTitleMatchMode", 2)
				
		WinWait("untitled - Paint", "Colors")
		If Not WinActive("untitled - Paint", "Colors") Then WinActivate("untitled - Paint", "Colors")
		WinSetTrans("untitled - Paint", "", 230)
		WinSetOnTop("untitled - Paint", "Colors", 1)
		WinWaitActive("untitled - Paint", "Colors")
		
    MouseMove(266, 403)
    MouseDown("left")
    MouseMove(1020, 737)
    MouseUp("left")
    MouseMove(38, 168)
    MouseDown("left")
    MouseUp("left")
    MouseMove(250, 115)
    MouseDown("left")
    MouseMove(827, 209)
    MouseUp("left")
    MouseMove(75, 703)
    MouseDown("left")
    MouseUp("left")
    MouseMove(300, 157)
    MouseDown("left")
    MouseUp("left")
    Send("This is only for learning purpose.")
    MouseMove(200, 392)
    MouseDown("left")
    MouseUp("left")

autoit.zip
(45.33 KiB) Downloaded 496 times
Last edited by Neo on Sat Mar 27, 2010 8:48 pm, edited 1 time in total.
Reason: Placed the attachement on the post using Place inline button
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Auto IT

Post by Neo » Sat Mar 27, 2010 8:52 pm

Interesting.... :) It is the first time that I heard of it thanks to our team mate RkskEkanayaka.
It's like an advanced batch processing script to me (kind of an advance .bat file)
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: Auto IT

Post by Rksk » Sun Mar 28, 2010 12:43 am

But anyone hasn't downloaded the code yet.

Mr. neo pls test it yourself and tell what you think!
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Auto IT

Post by Neo » Sun Mar 28, 2010 12:56 am

Very sorry on that. I'm too busy these days and will do that as time permits.
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: Auto IT

Post by Rksk » Sun Mar 28, 2010 12:58 am

Download AutoIT3 from here http://www.autoitscript.com/files/autoi ... -setup.exe

it is only 8MB !
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

CD tray controller

Post by Rksk » Mon Mar 29, 2010 10:32 am

There is an example code in AutoIT on CD tray controller.

After runnig this script, you will see a small bar on the Right corner of the screen. Move the moue point on to it. then you will see the window for controlling.

Code: Select all

#include-once
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <Timers.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Local $Button1, $Button2, $Button3, $Button4, $Button5, $btn1, $btn2, $btn3, $btn4, $btn5, $nMsg, $1, $2, $3, $4, $hi, $Form1, $romz, $1 = False, $2 = False, $3 = False, $4 = False, $5 = False
Local $Label1, $Label2, $Label3, $Label4, $Label5, $W, $Form,$Label, $a_mpos
$romz = DriveGetDrive("CDROM")
For $x = 1 To $romz[0]
	CDTray($romz[$x], "close")
Next
$W = @DesktopWidth - 200
up()
Func up()
$Form = GUICreate("Hidden", 116, 10, $W, 0, BitOR($WS_POPUP, $WS_BORDER, $DS_MODALFRAME), $WS_EX_TOPMOST)
$Label = GUICtrlCreateLabel("........", 2, 2,50, 10)
GUISetState(@SW_SHOW,$Form)
EndFunc

	While 1
	 $a_mpos = GUIGetCursorInfo($Form1)
	 If $a_mpos[4] = $Label Then
		 GUISetState(@SW_HIDE,$Form)
		 ExitLoop
		 EndIf
	WEnd


Switch $romz[0]
	Case "0"
		MsgBox(0, "Error", "No CD Drives Found")
		Exit
	Case "1"
		$1 = True
		$hi = 50
	Case "2"
		$2 = True
		$hi = 90
	Case "3"
		$3 = True
		$hi = 130
	Case "4"
		$4 = True
		$hi = 170

	Case "5"
		$5 = True
		$hi = 210


EndSwitch
   
_lb()
Func _lb()

	#Region ### START Koda GUI section ### Form=
	$Form1 = GUICreate("Form1", 116, $hi, $W, 0, BitOR($WS_POPUP, $WS_BORDER, $DS_MODALFRAME), $WS_EX_TOPMOST)
	Switch $romz[0]
		Case "0"
			MsgBox(0, "Error", "No CD Drives Found")
			Exit
		Case "1"

			$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)

		Case "2"

			$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
			$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
			$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)

		Case "3"

			$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
			$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
			$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
			$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
			$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)

		Case "4"

			$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
			$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
			$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
			$Button4 = GUICtrlCreateButton("Open (" & StringUpper($romz[4]) & ") ", 8, 136, 97, 25, 0)
			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
			$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
			$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
			$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)


		Case "5"

			$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
			$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
			$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
			$Button4 = GUICtrlCreateButton("Open (" & StringUpper($romz[4]) & ") ", 8, 136, 97, 25, 0)
			$Button5 = GUICtrlCreateButton("Open (" & StringUpper($romz[5]) & ") ", 8, 176, 97, 25, 0)
			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
			$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
			$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
			$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
			$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)


	EndSwitch
			DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 1000, "long", 0x00040004);slide in from left
			GUISetState(@SW_SHOW, $Form1)
	
	#EndRegion ### END Koda GUI section ###
;~ 	_Timer_SetTimer($Form1, 1000, "_update()")
EndFunc   ;==>_lb

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			If $1 = True Or $2 = True Or $3 = True Or $4 = True Or $5 = True Then
				$btn1 = _GUICtrlButton_GetText($Button1)
				If $btn1 = "Close (" & $romz[1] & ") " Then

					CDTray($romz[1], "close")
					_GUICtrlButton_SetText($Button1, "Open (" & StringUpper($romz[1]) & ") ")
					$Label1 = GUICtrlCreateLabel("", 8, 0, 100, 17, $SS_CENTER)
				Else
					CDTray($romz[1], "open")
					_GUICtrlButton_SetText($Button1, "Close (" & StringUpper($romz[1]) & ") ")
					$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
				EndIf
			EndIf
		Case $Button2
			If $2 = True Or $3 = True Or $4 = True Or $5 = True Then
				$btn2 = _GUICtrlButton_GetText($Button2)
				If $btn2 = "Close (" & $romz[2] & ") " Then

					CDTray($romz[2], "close")
					_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[2]) & ") ")
					$Label2 = GUICtrlCreateLabel("", 8, 40, 100, 17, $SS_CENTER)
				Else
					CDTray($romz[2], "open")
					_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[2]) & ") ")
					$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
				EndIf
			EndIf
		Case $Button3
			If $3 = True Or $4 = True Or $5 = True Then
				$btn3 = _GUICtrlButton_GetText($Button3)
				If $btn3 = "Close (" & $romz[3] & ") " Then

					CDTray($romz[3], "close")
					_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[3]) & ") ")
					$Label3 = GUICtrlCreateLabel(""), 8, 80, 100, 17, $SS_CENTER)
				Else
					CDTray($romz[3], "open")
					_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[3]) & ") ")
					$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
				EndIf
			EndIf

		Case $Button4
			If $4 = True Or $5 = True Then
				$btn4 = _GUICtrlButton_GetText($Button4)
				If $btn4 = "Close (" & $romz[4] & ") " Then

					CDTray($romz[4], "close")
					_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[4]) & ") ")
					$Label4 = GUICtrlCreateLabel("", 8, 120, 100, 17, $SS_CENTER)
				Else
					CDTray($romz[4], "open")
					_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[4]) & ") ")
					$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
				EndIf
			EndIf

		Case $Button5
			If $5 = True Then
				$btn5 = _GUICtrlButton_GetText($Button5)
				If $btn5 = "Close (" & $romz[5] & ") " Then

					CDTray($romz[5], "close")
					_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[5]) & ") ")
					$Label5 = GUICtrlCreateLabel("", 8, 160, 100, 17, $SS_CENTER)
				Else
					CDTray($romz[5], "open")
					_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[5]) & ") ")
					$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)
				EndIf
			EndIf


	EndSwitch
WEnd

Func _update()
 			$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
			$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
 			$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
 			$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
 			$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)
EndFunc	


User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

A guid to learn Auto IT (01)

Post by Rksk » Mon Apr 05, 2010 5:12 pm

First we can study a simple automation script.
It Plays with the calculator.

There is the code with step by step descriptions.

if you have any question reply in this post.

Code: Select all


; Script Function:
;   Plays with the calculator.
;


; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run the calculator and type in 2 x 4 x 8 x 16 and then quit.  Run?")


; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")
    Exit
EndIf


; Run the calculator
Run("calc.exe")


; Wait for the calulator become active - it is titled "Calculator" on English systems
WinWaitActive("Calculator")


; Now that the calc window is active type 2 x 4 x 8 x 16
; Use AutoItSetOption to slow down the typing speed so we can see it :)
AutoItSetOption("SendKeyDelay", 400)
Send("2*4*8*16=")
Sleep(2000) 


; Now quit by sending a "close" request to the calc
WinClose("Calculator")


; Now wait for calc to close before continuing
WinWaitClose("Calculator")


; Finished!

User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

A guid to learn Auto IT (02)

Post by Rksk » Mon Apr 05, 2010 5:16 pm

My second example Plays with the notepad.

There is the code with step by step descriptions.

if you have any question reply in this post.

Code: Select all


; Script Function:
;   Opens Notepad, types in some text and then quits.
;


; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run Notepad type in some text and then quit.  Run?")


; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")
    Exit
EndIf


; Run Notepad
Run("notepad.exe")


; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("[CLASS:Notepad]")


; Now that the Notepad window is active type some text
Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")
Sleep(500)
Send("+{UP 2}")
Sleep(500)


; Now quit by pressing Alt-f and then x (File menu -> Exit)
Send("!f")
Send("x")


; Now a screen will pop up and ask to save the changes, the window is called
; "Notepad" and has some text "Yes" and "No"
WinWaitActive("Notepad")
Send("n")


; Now wait for Notepad to close before continuing
WinWaitClose("[CLASS:Notepad]")


; Finished!

Post Reply

Return to “.Net & Other Programming”