[AutoIt] Some Simple Script Examples 11-14-2011, 11:43 PM
#1
Im Learning to use AutoIt Fairly Quickly. In the Process of Learning i Create some Example Scripts. These Are Basic and Use Very Little Code. Except the GUI. xD
- A Mouse Move Example. On Launch, You Enter the Coordinates of the Location to Move the Mouse to on the Desktop. (Uses InputBox as Well)
- Protected Notepad. This is Another Example of Using InputBox And A Variable to Check that the Correct Password Was Entered before Opening Notepad.
- A Sample GUI. It Doesnt Really Do Anything. It Just Uses 3 Radio Buttons and You Choose One to Change the GUI BG Color to.
- A Color Select Example. Brings up a Color Pallette in the GUI and You Use it To Select a Color to Change the BG of the GUI to.
- Create a Shortcut. Opens a Dialog and You Choose a File to Create a Shortcut of. You Also Name it.
I dont Know if these Will help, But Here you Go.
- A Mouse Move Example. On Launch, You Enter the Coordinates of the Location to Move the Mouse to on the Desktop. (Uses InputBox as Well)
Code:
$x = InputBox("Move Mouse", "Enter X Value to Move Mouse to.")
$y = InputBox("Move Mouse", "Enter Y Value to Move Mouse to.")
MouseMove($x ,$y, 20)- Protected Notepad. This is Another Example of Using InputBox And A Variable to Check that the Correct Password Was Entered before Opening Notepad.
Code:
$guess = InputBox("Open Notepad", "Enter the Correct Password to Open Notepad. A Wrong Password Will Exit This Application.", "", "*")
if $guess = "edit" Then
Run("notepad.exe")
Else
Exit
EndIf- A Sample GUI. It Doesnt Really Do Anything. It Just Uses 3 Radio Buttons and You Choose One to Change the GUI BG Color to.
Code:
include <GUIConstants.au3>
MainGUI()
Func MainGUI()
GUICreate("ReaperX's Test GUI")
$file = GUICtrlCreateMenu("File")
$file_notepad = GUICtrlCreateMenuItem("Open Notepad", $file)
$file_computer = GUICtrlCreateMenuItem("Open My Computer", $file)
$file_exit = GUICtrlCreateMenuItem("Exit", $file)
$actions = GUICtrlCreateMenu("Actions")
$actions_txt_file = GUICtrlCreateMenuItem("Open Text File", $actions)
$actions_calc = GUICtrlCreateMenuItem("Open Calculator", $actions)
$help = GUICtrlCreateMenu("Help")
$help_about = GUICtrlCreateMenuItem("About", $help)
$tab_set = GUICtrlCreateTab(110, 100, 135, 150)
$tab_1 = GUICtrlCreateTabItem("Change BG")
$bg_red_radio = GUICtrlCreateRadio("Red", 115, 125)
$bg_green_radio = GUICtrlCreateRadio("Green", 115, 145)
$bg_yellow_radio = GUICtrlCreateRadio("Yellow", 115, 165)
$tab_2 = GUICtrlCreateTabItem("AutoIt Info")
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
If $msg = $file_notepad Then
$file = Run("notepad.exe")
EndIf
if $msg = $file_computer Then
$file = Run("explorer.exe")
EndIf
If $msg = $file_exit Then
Exit
EndIf
If $msg = $actions_txt_file Then
$txt_file_1 = FileOpenDialog("Choose a Text File to Open...", @DesktopDir, "Text Files(*.txt)")
FileOpen($txt_file_1)
EndIf
If $msg = $actions_calc Then
Run("calc.exe")
EndIf
If $msg = $help_about Then
$help = MsgBox(0, "About", "This Test GUI Was Created by ReaperX")
EndIf
Select
Case $msg = $bg_red_radio
GUISetBkColor(0xED1C24)
Case $msg = $bg_green_radio
GUISetBkColor(0x22B14C)
Case $msg = $bg_yellow_radio
GUISetBkColor(0xFFF200)
EndSelect
WEnd
EndFunc- A Color Select Example. Brings up a Color Pallette in the GUI and You Use it To Select a Color to Change the BG of the GUI to.
Code:
#Include <GUIConstants.au3>
#Include <Misc.au3>
GUICreate("Choose Color")
$button = GUICtrlCreateButton("Choose Color", 150, 150)
$iReturnType = 2
GUISetState()
While 1
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE Then Exit
Select
Case $msg = $button
$color = _ChooseColor($iReturnType)
GUISetBkColor($color)
EndSelect
WEnd- Create a Shortcut. Opens a Dialog and You Choose a File to Create a Shortcut of. You Also Name it.
Code:
$message = "Find a File to Create a Shortcut Of."
$file = FileOpenDialog($message, @WindowsDir & "\", "All Files(*.*)",0)
$name = InputBox("Shortcut Name", "Enter the Desired Name of the Shortcut.")
If @error Then
MsgBox(0, "Error!", "No File Was Chosen")
Exit
EndIf
ProgressOn("Creating Shortcut", "Progress", "0%")
for $i = 1 to 100 step 100
sleep(1000)
ProgressSet($i, "Creating...", "Progress")
Next
ProgressSet(100, "Created!", "Complete")
Sleep(500)
ProgressOff()
$shortcut = FileCreateShortcut($file, $name)
MsgBox(0, "Success!", "Shortcut Created In Directory Of File.")I dont Know if these Will help, But Here you Go.
(This post was last modified: 11-16-2011, 02:07 AM by doojan.)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)