;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; AutoIt Version: 3.0 ; Language: English ; Platform: Windows 2019/10/2016/8/2012/7/2008 ; Author: Core Technologies Consulting, LLC ; ; Script Function: ; Clicks a given button on a given window ; ; Usage: ; ClickButton [-d] ; where the optional -d flag specifies to show debugging ; information. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Expect at least 2 arguments, the window and button names ; Exit if less than 2 arguments if $CmdLine[0] < 2 Then MsgBox(0x40000, 'ClickButton', 'Usage:' & @CRLF & @CRLF & 'ClickButton [-d]') Exit(1) EndIf $windowName = $CmdLine[1] $buttonName = $CmdLine[2] ; If the 3rd argument is -d, then show debug $showDebug = "no" if $CmdLine[0] >=3 Then if $CmdLine[3] = "-d" Then $showDebug = "yes" Endif EndIf if $showDebug = "yes" Then MsgBox(0x40000, 'ClickButton', 'Parameters:' & @CRLF & @CRLF & 'Window name = "' & $windowName & '"' & @CRLF & 'Button name = "' & $buttonName & '"') EndIf ; Try to activate the window. May not succeed in Session 0: ; https://www.coretechnologies.com/blog/miscellaneous/running-autoit-session-0/ if (WinActivate($windowName)) Then if $showDebug = "yes" Then MsgBox(0x40000, 'ClickButton', 'Window "' & $windowName & '" found, clicking the "' & $buttonName & '" button.') EndIf Else if $showDebug = "yes" Then MsgBox(0x40000, 'ClickButton', 'Window "' & $windowName & '" NOT found. Trying to click anyway.') EndIf EndIf ; Click the button ControlClick($windowName, $buttonName, "")