#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $BtClickFlg=True ;Declare a global variable ,if button clicked, this global variable will control the function not to run again.
$Form1 = GUICreate("Form1", 122, 196, 192, 114) ;create form
$Button1 = GUICtrlCreateButton("Myfirst BT", 8, 8, 105, 41) ;create button
$Button2 = GUICtrlCreateButton("Mysecond BT", 8, 72, 105, 41)
$Button3 = GUICtrlCreateButton("Mythird BT", 8, 136, 105, 41)
GUISetState(@SW_SHOW) ;show form
#EndRegion ### END Koda GUI section ###
$stringtoclickbt=InputBox("Input","Please input which button you want to click:","","",300,80) ;input the letter on the button which you want to click
While 1 ;message loop
$nMsg = GUIGetMsg() ;get message
Switch $nMsg ;switch message
Case $GUI_EVENT_CLOSE ;if message is $GUI_EVENT_CLOSE,exit program
Exit
Case $Button1 ;if message is button1
MsgBox(0,"Button1 Click","You clicked button1!") ;show a messagebox, title is 'button1 click',text is 'You clicked button1!'
$BtClickFlg=False ;set button click flg to false,the function just run once
Case $Button2
MsgBox(0,"Button2 Click","You clicked button2!")
$BtClickFlg=False
Case $Button3
MsgBox(0,"Button3 Click","You clicked button3!")
$BtClickFlg=False
EndSwitch
If $BtClickFlg=True Then ;if button click flg is true , call function clickbutton to Sends a mouse click command to the button witch you type in the inputbox
clickbutton($stringtoclickbt)
EndIf
WEnd
Func clickbutton($stringonbutton)
Local $string1=GUICtrlRead($Button1) ;Declare a local variable ,set the value is button1's text
Local $string2=GUICtrlRead($Button2) ;Declare a local variable ,set the value is button2's text
Local $string3=GUICtrlRead($Button3) ;Declare a local variable ,set the value is button3's text
If $stringonbutton=$string1 Then ;if button1's text is same to the string you type in, Sends a mouse click command to button1
ControlClick($Form1,"",$Button1,"left")
EndIf
If $stringonbutton=$string2 Then ;if button2's text is same to the string you type in, Sends a mouse click command to button2
ControlClick($Form1,"",$Button2,"left")
EndIf
If $stringonbutton=$string3 Then ;if button3's text is same to the string you type in, Sends a mouse click command to button3
ControlClick($Form1,"",$Button3,"left")
EndIf
EndFunc