Jump to content

Wait for user to push button


KalleB
 Share

Recommended Posts

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.
 

GUISetState(@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

 

Link to comment
Share on other sites

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
EndFunc

for 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)

Link to comment
Share on other sites

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
EndFunc

for further help feel free to ask

Hello

If 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.

Link to comment
Share on other sites

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 box

Try this: (if it is what you want)

#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)

Link to comment
Share on other sites

  • Moderators

KalleB,

As everything is within your own script, I would do something simple along these lines:

#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)

EndFunc

I think the code is self-explanatory, but please do ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...