KalleB Posted September 11, 2015 Posted September 11, 2015 I am using a script that loops through an array and checks one element on each row. If the value is verified to be correct (according to a list) then it continues. If the value can't be verified, then I open an InputBox for user interaction. In this case, the next line in the array isn't processed until I have submitted something.I would, however, want to do this with an input field and button inside a larger GUI. The GUI also contains a listview that gets updated after having looped through the entire array.What I can't do is pause the script to wait for user input with this method, the next line gets processed immediately. How can I wait for the button to be pressed?All elements are within my own GUI, no interaction with other applications in these parts.The first Func __Check demonstrates what works, the second what doesn't. expandcollapse popupGUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit 0 Case $button $iWait = 0 WEnd For $i = 1 to UBound($array) MsgBox(0, "", $i) __Check($array[$i]) Next _GUICtrlListViewCreateItem($listView, $number) Func __Check($element) $iCheck = _ArraySearch($list, $element) If $iCheck > -1 Then Return $element Else $sTemp = InputBox("Correct this", "This needs correction", $element) Return $sTemp EndIf EndFunc Func __Check($element) $iCheck = _ArraySearch($list, $element) If $iCheck > -1 Then Return $element Else $iWait = 1 GUICtrlSetData($inputBox, $element) Do Sleep(10) Until $iWait = 0 Return GUICtrlRead($inputBox) EndIf EndFunc
Surya Posted September 11, 2015 Posted September 11, 2015 you mean,Like this:#include <WindowsConstants.au3> Local $press = False GUICreate ("") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_KEYDOWN,"down") do Sleep (50) Until $press MsgBox ("","","key pressed continuing...") ;other code here...... ;....... Func down() $press = True EndFuncfor further help feel free to ask No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
KalleB Posted September 11, 2015 Author Posted September 11, 2015 you mean,Like this:#include <WindowsConstants.au3> Local $press = False GUICreate ("") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_KEYDOWN,"down") do Sleep (50) Until $press MsgBox ("","","key pressed continuing...") ;other code here...... ;....... Func down() $press = True EndFuncfor further help feel free to askHelloIf I understand correctly, that waits for any key on the keyboard to be pressed? I want to wait until a specified button within the GUI is pressed, which often will be done after typing some text in the input field.If the list is Alaska - Alabama - Mexico - Texas - Florida - Canada, it should process Alaska and Alabama, then wait for me to (for example) enter New before Mexico, then continue with Texas and Florida before finally asking me to enter something else in Canada's place.If I do it with InputBox(), then it works fine, but I would like to skip the popups and handle it within my GUI.
Surya Posted September 12, 2015 Posted September 12, 2015 I want to wait until a specified button within the GUI is pressed, which often will be done after typing some text in the input field.So if i am correct you want to wait for a button to be pressed within the gui or when the gui is active and not when typing into input boxTry this: (if it is what you want)expandcollapse popup#include <WindowsConstants.au3> #include <WinAPI.au3> #include <String.au3> Local $press = False $key = "k" HotKeySet ($key,"down") $gui = GUICreate ("") GUICtrlCreateInput("",30,40) GUICtrlCreateButton ("Press this",100,100) GUISetState(@SW_SHOW) do Sleep (50) Until $press MsgBox ("","","key pressed continuing...") ;other code here...... ;....... Func down() If WinActive($gui) And Not StringCompare(_FocusCtrlID($gui),3) = 0 Then $press = True Else GUICtrlSetData(_FocusCtrlID($gui),"k") EndIf EndFunc Func _FocusCtrlID($hWnd, $sTxt = "") Local $hFocus = ControlGetHandle($hWnd, $sTxt, ControlGetFocus($hWnd, $sTxt)) If IsHWnd($hFocus) Then Return _WinAPI_GetDlgCtrlID($hFocus) Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_FocusCtrlID No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
Moderators Melba23 Posted September 12, 2015 Moderators Posted September 12, 2015 KalleB,As everything is within your own script, I would do something simple along these lines:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; Create an array to test Global $aArray[20] For $i = 0 To 19 $aArray[$i] = "Element " & $i Next $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("Array Elements As Checked", 10, 10, 200, 200) $cInput = GUICtrlCreateInput("", 10, 250, 200, 20) GUICtrlSetState($cInput, $GUI_DISABLE) $cAccept = GUICtrlCreateButton("Accept Edit", 10, 300, 80, 30) GUICtrlSetState($cAccept, $GUI_DISABLE) $cCancel = GUICtrlCreateButton("Cancel Edit", 100, 300, 80, 30) GUICtrlSetState($cCancel, $GUI_DISABLE) $cStart = GUICtrlCreateButton("Start", 10, 400, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cStart For $i = 0 To UBound($aArray) - 1 _TestElement($i) Next EndSwitch WEnd Func _TestElement($iElementIndex) $sText = $aArray[$iElementIndex] If StringRight($sText, 1) = "7" Then ; A simple test to allow for editing GUICtrlSetState($cInput, $GUI_ENABLE) GUICtrlSetState($cAccept, $GUI_ENABLE) GUICtrlSetState($cCancel, $GUI_ENABLE) GUICtrlSetData($cInput, $sText) While 1 Switch GUIGetMsg() Case $cAccept $aArray[$iElementIndex] = GUICtrlRead($cInput) ExitLoop Case $cCancel ExitLoop EndSwitch WEnd GUICtrlSetState($cInput, $GUI_DISABLE) GUICtrlSetState($cAccept, $GUI_DISABLE) GUICtrlSetState($cCancel, $GUI_DISABLE) GUICtrlSetData($cInput, "") EndIf GUICtrlCreateListViewItem($aArray[$iElementIndex], $cLV) EndFuncI think the code is self-explanatory, but please do ask if you have any questions.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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