Pages

Showing posts with label autoit. Show all posts
Showing posts with label autoit. Show all posts

Monday, November 23, 2009

AutoIt script to execute on key combination event

     For the Programming section of SecurityOverride, you are required to make a script to resolve a task, given a random input, in a short time, 10-15 seconds.  The method I've used for all the challenges:  I've written an AutoIt  script that:
  • stays active when run
  • after a keyboard combination is pressed:
    • copies the selected text into clipboard
    • gets it, and executes a function on it
    • puts the result in the clipboard
Example for challenge1:


         In order to complete Programming Challenge 1, you must code a script that will reverse the string below, while maintaining the first letter at the beginning.
         Example: chicken -> cnekcih


#comments-start
#comments-start
 ;---------------------------------------
 Autorun program on Ctrl+C event (for SecurityOverride programming)
 ;---------------------------------------
#comments-end 

HotKeySet("^{F1}", "Solve")
Global $input

While 1
 Sleep(10000)
WEnd


Func Solve()
 GetInput()
 ParseInput()
 Exit(0)
EndFunc

Func GetInput()
 Send("^{c}")
 $input = ClipGet()
EndFunc

Func ParseInput()  
 Local $a = StringToASCIIArray($input)
 Local $len = StringLen($input)
 Local $i, $j = 1
 Dim $rez[$len]
 
 $rez[0] = $a[0]
 For $i = $len-1 to 1 Step -1
   $rez[$j] = $a[$i]
   $j = $j + 1
 Next
 
 ClipPut(StringFromASCIIArray($rez))
EndFunc

; cnekcih


References: 

  1. AutoIt official site
  2. Scite IDE for AutoIt3
  3. Great site: SecurityOverride

Sunday, September 13, 2009

How to automate tasks with AutoIt AU3Recorder

   AutoIt allows recording of a series of action and then playing them back (recording a macro). Besides AutoIt, you need also the script editor (SciTE4AutoIt3). After you install both, run Scite, create a new file with .au3 extension, and run AU3 Recorder, either from the tools menu or with Alt+F6 combination (This option is not present if the file being edited is not au3).




This is a good start to begin automating simple things on windows. After crating the au3 script, it can be edited manually if it needs adjustments and then run every time.  


Any possible scenarios can be imagined and automated, starting from clicks and key combinations, installing programs, running tasks....
Great productivity increase:) 
Simple example of automation some browser stuff (selecting text, copying, open tabs,..):
Func Solve()
 Dim $i, $result, $input
 
 For $i = 5 To 1 Step -1
  ; Double left click at cursor position (mouse button swapped from Control Panel)
  MouseClick("right", Default, Default, 2)

  Send("^{c}")   ; Copy
  $input = ClipGet()  ; Get clipboard content
  $result = StringCompare($input, "fail", 1)
  If $result <> 0 Then
   Print($adr, 2000)
  EndIf

  Send("^{t}")   ; Open new tab in browser 
  Send($adr,0)    ; Type address
  Send("{ENTER}") ; Hit Enter
  
  Sleep(1000)
 Next
EndFunc    ; ==> Solve()

Func Print($string, $time)
 ToolTip($string)
 Sleep($time)
 ToolTip("")
EndFunc   ;==>Print()
References: