notsacc Posted March 2, 2015 Posted March 2, 2015 Hi, I'm new to AutoIt and I've been trying to write a simple script but I'm an idiot when it comes to this as I've never written any code before and have no background. At work, I have to interface with this piece of crap program and want to automate text entries and button clicks using a simple GUI. I need to be able to hit a series of hotkeys (or click the GUI buttons) and, when I'm ready, hit a button or final hotkey which will execute the clicks and text sends. The number of buttons I click varies, sometimes 2, sometimes 10. What I had envisioned was to hotkey each button, and each hotkey was linked to a simple function that would move the mouse around and enter the text I need to enter. What happens now is that once the GUI launches, as soon as I hit the button or hotkey, it executes. I need it to queue up several buttons then execute them sequentially in the order I have pressed them but I'm far too stupid to figure out how to do this without some help. Once you've seen the really basic, redundant, (probably broken?) code I've written below you'll understand what you're dealing with, but thanks in advance for the help. expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Local $hGUI = GUICreate("Window", 600, 500, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") Local $hButton1 = GUICtrlCreateButton("Chicken", 150, 50, 114, 92) GUICtrlSetOnEvent($hButton1, "_Chick") Local $hButton2 = GUICtrlCreateButton("Toast", 270, 50, 114, 92) GUICtrlSetOnEvent($hButton2, "_Toast") Local $hButton3 = GUICtrlCreateButton("Ice", 150, 150, 114, 92) GUICtrlSetOnEvent($hButton3, "_Ice") Local $hButton4 = GUICtrlCreateButton("Moon", 270, 150, 114, 92) GUICtrlSetOnEvent($hButton4, "_Moon") Local $hButton5 = GUICtrlCreateButton("Blue", 150, 250, 114, 92) GUICtrlSetOnEvent($hButton5, "_Blue") Local $hButton6 = GUICtrlCreateButton("Write", 390, 350, 114, 92) GUICtrlSetOnEvent($hButton6, "_Write") Local $aAccelKeys[6][6] = [["{F1}", $hButton1],["{F2}", $hButton2],["{F3}", $hButton3],["{F4}", $hButton4],["{F5}", $hButton5]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(100) WEnd ;Need code that records the buttons clicks from above, in the order that they are pressed, then after the user hits the Write button, executes the Functions(mouseclicks and text sends) corresponding to those buttons. ;the user may not hit all the buttons every time, just maybe 2, then clicks write, 4 then clicks write Func _Exit() Sleep(100) Exit EndFunc Func _Chick() MouseClick("left",60,87,1) MouseClick("left",380,157,1) Send("asdfad") MouseClick("left",315,56,1) MouseClick("left",380,156,1) Send("asdfad") MouseClick("left",380,156,1) EndFunc Func _Toast() MouseClick("left",60,87,1) MouseClick("left",380,157,1) Send("toasttoast") EndFunc Func _Ice() MouseClick("left",60,87,1) MouseClick("left",380,157,1) Send("iceice") EndFunc Func _Moon() MouseClick("left",60,87,1) MouseClick("left",380,157,1) Send("moonmoon") EndFunc Func _Blue() MouseClick("left",60,87,1) MouseClick("left",380,157,1) Send("blueblue") EndFunc Func _Write() ; EndFunc
spudw2k Posted March 2, 2015 Posted March 2, 2015 Sounds like a potential timing nightmare...and even more so peculiar with the names you used in your example. So, you need a queuing mechanism. One way would be to create an array with the "sequence" then enumerate through the array and execute each function. You could easily create an array by creating a string and appending to it (using a separator for each entry) and then using StringSplit to generate the array. You could then use the Call function to run each function in the sequence. As an example... $sSequence = "_Chick|_Toast|" $aSequence = StringSplit($sSequence, "|") For $sFunc In $aSequence Call($sFunc) Next Func _Chick() ConsoleWrite("_Chick" & @CRLF) EndFunc Func _Toast() ConsoleWrite("_Toast" & @CRLF) EndFunc This is just a quick and dirty way, but I figured it would give you some ideas. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now