ckelsoe Posted July 21, 2013 Share Posted July 21, 2013 Hi, I am new to AutoIt. I am working on automating some functionality for a web app. When a specific web page opens I want to display a gui for the user to select several options that will be passed to the web page. I am unclear on how to have the gui "hidden" and only show up when the active page is on the monitor. I am thinking that this needs to be done on a timer but I am just not sure how to go about it. For testing I see this being the code to open the GUI: Func WaitForNotepad If WinActivate("Untitled - Notepad")Then GUISetState(@SW_SHOW) Return EndIf EndFunc In this case I want the gui to show when the active window is Notepad. But how do I get the script to "sleep" until notepad is open. Thanks in advance. Link to comment Share on other sites More sharing options...
FireFox Posted July 22, 2013 Share Posted July 22, 2013 Hi, Welcome to the autoit forum Here you go :#include <GUIConstantsEx.au3> Local $blGUIShowed = False Local $hGUI = GUICreate("MyGUI") Local $hWnd = 0 ;main loop which will be executed until you close the GUI While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) $hWnd = WinGetHandle("Untitled - Notepad") ;If the window exists then the handle will be upper 0 If Not $blGUIShowed And $hWnd > 0 Then GUISetState(@SW_SHOW, $hGUI) $blGUIShowed = True ElseIf $blGUIShowed And $hWnd = 0 Then GUISetState(@SW_HIDE, $hGUI) $blGUIShowed = False EndIf WEnd GUIDelete($hGUI) Link to comment Share on other sites More sharing options...
ckelsoe Posted July 22, 2013 Author Share Posted July 22, 2013 Ok that is exactly what I needed. However, I am having trouble integrating that code in with the standard loop code. See below: While 1 ; Used to display the GUI when the Commissions Window is open. While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) $hWnd = WinGetHandle("Untitled - Notepad") ;If the window exists then the handle will be upper 0 If Not $blGUIShowed And $hWnd > 0 Then GUISetState(@SW_SHOW, $hGUI) $blGUIShowed = True $nMsg = GUIGetMsg() For $lNum = 0 To 9 If $nMsg = $ctrlButton[$lNum] Then GUICtrlSetData($ctrlInput, GUICtrlRead($ctrlInput) & $lNum) Next Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ctrlDecimal _AddChar($ctrlInput, ".") Case $CtrlSetCustomRate If StringLen(GUICtrlRead($ctrlInput)) = 0 Then MsgBox(16, "No Commission Rate Specificed", "No commission rate was entered. You must enter a custom commission rate.") Else MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") EndIf Case $CtrlClearCustomRate GUICtrlSetData($ctrlInput, "") EndSwitch ElseIf $blGUIShowed And $hWnd = 0 Then GUISetState(@SW_HIDE, $hGUI) $blGUIShowed = False EndIf WEnd WEnd Where do I incorporate your code with the standard switch that I have started my coding in? BTW, Thank you very much for the help. Link to comment Share on other sites More sharing options...
TheSaint Posted July 22, 2013 Share Posted July 22, 2013 Welcome! Further to what FireFox has provided, which should be an excellent starting point for you, you perhaps need to indicate the following. [1] Will the program be running 24/7? [2] If not, then how is the program started? [3] What browsers will you be catering for? [4] etc With the above, you could be using commands like - ProcessExist, WinExist, WinActive, etc. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
ckelsoe Posted July 22, 2013 Author Share Posted July 22, 2013 THanks for the quick response. The web application runs in Internet Explorer only. Internet Explorer and the application will be loaded before any AutoIt script is launched. There is another AutoIt script that is a dashboard per say in which the user will click to search for a record, do other edits, etc. This GUI will only be needed and seen when the user clicks a button in the main web ui. When that popup window is active the user should see this GUI next to the popup with basically a couple of buttons for predefined commission rates (100, 50, 0) and a text field with buttons 0-9, decimal, clear, and ok. Clicking one of the predefined buttons initiates an edit by moving the mouse to a field, sending text (100, 20, or 0), moving the mouse to a post button, and clicking the post button which closes the popup. The user can also enter other commission rates by clicking on 0-9 and the decimal. Those values are stuffed into a text box so they can see what they have entered. Pressing the OK button will then perform the same mouse movements and clicking and sending of text as the predefined buttons will. The program will run for as long as the user is editing data - which on this project can be 8-16 hours per day - depending when they are paying overtime. I do use WinActive in the dashboard code to make sure the specific window is opened before sending keys and mouse movements. I now am trying to minimize the gui and where the gui's are at so the mouse movement for the user is less. Here is a sample image of what I am looking to achieve: Well scratch that - the forums does not like links to jpg or png. Link to comment Share on other sites More sharing options...
ckelsoe Posted July 22, 2013 Author Share Posted July 22, 2013 Here is the full code so you can see the GUI, etc. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; The following three vars are used to show GUI as needed. Local $blGUIShowed = False ; Local $hGUI = GUICreate("MyGUI") --> in GI code below. Local $hWnd = 0 #region### GUI Region Local $hGUI = GUICreate("IMT Commission Panel", 242, 475, -1696, 182) Global $ctrlButton[11] $grpQuickCommission = GUICtrlCreateGroup("Custom Commission Rate", 8, 88, 225, 377) $ctrlInput = GUICtrlCreateInput("", 16, 112, 65, 53) GUICtrlSetFont(-1, 20, 400, 0, "Segoe UI") $CtrlClearCustomRate = GUICtrlCreateButton("r", 88, 104, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Webdings") GUICtrlSetColor(-1, 0xFF0000) $ctrlButton[1] = GUICtrlCreateButton("1", 16, 176, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[2] = GUICtrlCreateButton("2", 88, 176, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[3] = GUICtrlCreateButton("3", 160, 176, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[4] = GUICtrlCreateButton("4", 16, 248, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[5] = GUICtrlCreateButton("5", 88, 248, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[6] = GUICtrlCreateButton("6", 160, 248, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[7] = GUICtrlCreateButton("7", 16, 320, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[8] = GUICtrlCreateButton("8", 88, 320, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[9] = GUICtrlCreateButton("9", 160, 320, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $ctrlButton[0] = GUICtrlCreateButton("0", 16, 392, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $CtrlSetCustomRate = GUICtrlCreateButton("a", 160, 104, 65, 65) GUICtrlSetFont(-1, 40, 400, 0, "Webdings") GUICtrlSetColor(-1, 0x008000) $ctrlDecimal = GUICtrlCreateButton(".", 88, 392, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $CtrlGroupQuickCommission = GUICtrlCreateGroup("1-Click Quick Commission Rate", 8, 0, 225, 89) $Ctrl100 = GUICtrlCreateButton("100", 16, 16, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $CtrlZero = GUICtrlCreateButton("0", 88, 16, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") $Ctrl50 = GUICtrlCreateButton("50", 160, 16, 65, 65) GUICtrlSetFont(-1, 24, 400, 0, "Segoe UI") GUICtrlCreateGroup("", -99, -99, 1, 1) ; GUISetState(@SW_SHOW, $hGUI) --> Moved to loop for this GUI #endregion### GUI Region While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) $hWnd = WinGetHandle("Untitled - Notepad") ;If the window exists then the handle will be upper 0 If Not $blGUIShowed And $hWnd > 0 Then GUISetState(@SW_SHOW, $hGUI) $blGUIShowed = True $nMsg = GUIGetMsg() For $lNum = 0 To 9 If $nMsg = $ctrlButton[$lNum] Then GUICtrlSetData($ctrlInput, GUICtrlRead($ctrlInput) & $lNum) Next Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ctrlDecimal _AddChar($ctrlInput, ".") Case $CtrlSetCustomRate If StringLen(GUICtrlRead($ctrlInput)) = 0 Then MsgBox(16, "No Commission Rate Specificed", "No commission rate was entered. You must enter a custom commission rate.") Else ' Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") EndIf Case $CtrlClearCustomRate GUICtrlSetData($ctrlInput, "") Case $Ctrl100 ' Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") Case $CtrlZero ' Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") Case $Ctrl50 ' Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") EndSwitch ElseIf $blGUIShowed And $hWnd = 0 Then GUISetState(@SW_HIDE, $hGUI) $blGUIShowed = False EndIf ; How do I end this at the end of the day?? Perhaps keep it running until the mail web page is gone. WEnd Func _AddChar($aID, $aChar) If _CheckLast($aID) = 1 Then GUICtrlSetData($aID, GUICtrlRead($aID) & $aChar) EndFunc ;==>_AddChar Func _CheckLast($aID) Local $lRead = GUICtrlRead($aID) Local $lRight = StringRight($lRead, 1) Switch $lRight Case "*", "/", "-", "+", "^", "." Return 0 Case Else Return 1 EndSwitch EndFunc ;==>_CheckLast Link to comment Share on other sites More sharing options...
Solution FireFox Posted July 22, 2013 Solution Share Posted July 22, 2013 You only need one GUIGetMsg, place it outside any expression. I cleaned your code btw.expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; The following vars are used to show GUI as needed. Local $blGUIShowed = False Local $hWnd = 0 #region### GUI Region Local $hGUI = GUICreate("IMT Commission Panel", 242, 475, -1696, 182) Local $ctrlButton[11], $grpQuickCommission = 0, $ctrlInput = 0, $CtrlClearCustomRate = 0, _ $CtrlSetCustomRate = 0, $ctrlDecimal = 0, $CtrlGroupQuickCommission = 0, $CtrlZero = 0, $Ctrl50 = 0, $Ctrl100 = 0 $grpQuickCommission = GUICtrlCreateGroup("Custom Commission Rate", 8, 88, 225, 377) $ctrlInput = GUICtrlCreateInput("", 16, 112, 65, 53) GUICtrlSetFont($ctrlInput, 20, 400, 0, "Segoe UI") $CtrlClearCustomRate = GUICtrlCreateButton("r", 88, 104, 65, 65) GUICtrlSetFont($CtrlClearCustomRate, 24, 400, 0, "Webdings") GUICtrlSetColor($CtrlClearCustomRate, 0xFF0000) Local $aPos[10][2] = [[16, 392], [16, 176], [88, 176], [160, 176], [16, 248], [88, 248], [160, 248], [16, 320], [88, 320], [160, 320]] For $i = 0 To 9 $ctrlButton[$i] = GUICtrlCreateButton($i, $aPos[$i][0], $aPos[$i][1], 65, 65) GUICtrlSetFont($ctrlButton[$i], 24, 400, 0, "Segoe UI") Next $CtrlSetCustomRate = GUICtrlCreateButton("a", 160, 104, 65, 65) GUICtrlSetFont($CtrlSetCustomRate, 40, 400, 0, "Webdings") GUICtrlSetColor($CtrlSetCustomRate, 0x008000) $ctrlDecimal = GUICtrlCreateButton(".", 88, 392, 65, 65) GUICtrlSetFont($ctrlDecimal, 24, 400, 0, "Segoe UI") $CtrlGroupQuickCommission = GUICtrlCreateGroup("1-Click Quick Commission Rate", 8, 0, 225, 89) $Ctrl100 = GUICtrlCreateButton("100", 16, 16, 65, 65) GUICtrlSetFont($Ctrl100, 24, 400, 0, "Segoe UI") $CtrlZero = GUICtrlCreateButton("0", 88, 16, 65, 65) GUICtrlSetFont($CtrlZero, 24, 400, 0, "Segoe UI") $Ctrl50 = GUICtrlCreateButton("50", 160, 16, 65, 65) GUICtrlSetFont($Ctrl50, 24, 400, 0, "Segoe UI") GUICtrlCreateGroup("", -99, -99, 1, 1) #endregion### GUI Region Local $iMsg = 0 While 1 Sleep(10) $hWnd = WinGetHandle("Untitled - Notepad") ;If the window exists then the handle will be upper 0 If Not $blGUIShowed And $hWnd > 0 Then GUISetState(@SW_SHOW, $hGUI) $blGUIShowed = True ElseIf $blGUIShowed And $hWnd = 0 Then GUISetState(@SW_HIDE, $hGUI) $blGUIShowed = False EndIf $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $ctrlDecimal _AddChar($ctrlInput, ".") Case $CtrlSetCustomRate If StringLen(GUICtrlRead($ctrlInput)) = 0 Then MsgBox(16, "No Commission Rate Specificed", "No commission rate was entered. You must enter a custom commission rate.") Else ; Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") EndIf Case $CtrlClearCustomRate GUICtrlSetData($ctrlInput, "") Case $Ctrl100 ; Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") Case $CtrlZero ; Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") Case $Ctrl50 ; Displaying message box until the logic is worked out. Will send keys and mouse here. MsgBox(64, "Custom Rate", "The custom rate is " & GUICtrlRead($ctrlInput) & "%") Case Else For $lNum = 0 To 9 If $iMsg = $ctrlButton[$lNum] Then GUICtrlSetData($ctrlInput, GUICtrlRead($ctrlInput) & $lNum) Next EndSwitch WEnd GUIDelete($hGUI) Func _AddChar($aID, $aChar) If _CheckLast($aID) = 1 Then GUICtrlSetData($aID, GUICtrlRead($aID) & $aChar) EndFunc ;==>_AddChar Func _CheckLast($aID) Local $lRead = GUICtrlRead($aID) Local $lRight = StringRight($lRead, 1) Switch $lRight Case "*", "/", "-", "+", "^", "." Return 0 Case Else Return 1 EndSwitch EndFunc ;==>_CheckLast Link to comment Share on other sites More sharing options...
ckelsoe Posted July 22, 2013 Author Share Posted July 22, 2013 Ah - perfect. And thanks for the code cleanup. The form code was from Koda (not sure if that is the best one). Next step is to see if I can figure out the IE stuff to look for text on a page so I can see where I am - this is for another part of the project. Anyhow - Thank you very very much! Link to comment Share on other sites More sharing options...
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