Sign in to follow this  
Followers 0
EndFunc

Control Focus with Input

11 posts in this topic

I for the life of me can't get the focus to work correct on an input form.

I created a change password form with two input fields and 2 buttons.

I want the ok button to be available so after to finish typing in the fields you can just hit enter and not have to tab first.

Anybody got any good solutions. Searched but didn't find antying of use so far.

Tried,

_GUICtrlButton_SetFocus


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites



See HotKeySet.

Share this post


Link to post
Share on other sites

Add "#include <ButtonConstants.au3>" to your script and include the $BS_DEFPUSHBUTTON style on the OK button. Hitting ENTER should react the same as clicking OK.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

See HotKeySet.

Thanks, that might be helpful, but... its a form within a form. I have an application and when you click the button it opens another gui which is the change password form. Won't the hotkeyset affect the overall app?


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

It will, but you can see what is the active window by doing something like this within the HotKeySet function body:

If WinGetHandle('[ACTIVE]') = $hForm2 Then
    ; GUICtrlSendMsg(...)
EndIf

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Add "#include <ButtonConstants.au3>" to your script and include the $BS_DEFPUSHBUTTON style on the OK button. Hitting ENTER should react the same as clicking OK.

:D

Thanks but this just seems to change the style/look but it doesn't do anything when I press enter if the input field has the focus. Am I doing something wrong?

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Thanks but this just seems to change the style/look but it doesn't do anything when I press enter if the input field has the focus. Am I doing something wrong?

It looks like this is only for a dialog box. I created a form with 2 input fields and buttons to make my own custom form. Should it work regardless?


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

It looks like this is only for a dialog box. I created a form with 2 input fields and buttons to make my own custom form. Should it work regardless?

Post a very short, basic reproducer script. Just two inputs and an OK button, with a description of what it doesn't do. I'm sure we can make it go.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Post a very short, basic reproducer script. Just two inputs and an OK button, with a description of what it doesn't do. I'm sure we can make it go.

:D

Thanks, here the basic form. I basically want to be able type in the fields and just hit enter with OK being the default focus.

$Passform = GUICreate($AppName, 315, 200)
                        GUISetStyle($WS_CAPTION, 0)
                        $Password = GUICtrlCreateInput("", 29, 48, 257, 21, $ES_PASSWORD)
                        $Confirm = GUICtrlCreateInput("", 29, 102, 257, 21, $ES_PASSWORD)
                        $passlab = GUICtrlCreateLabel("Enter New Password", 32, 24, 103, 17)
                        $conflab = GUICtrlCreateLabel("Confirm New Password", 32, 85, 113, 17)
                        $OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, 0)
                        $cancel = GUICtrlCreateButton("Cancel", 183, 164, 105, 25, 0)
                        GUISetState(@SW_SHOW)
While 1
                            $nMsg = GUIGetMsg()
                            Switch $nMsg
                                Case $GUI_EVENT_CLOSE
                                    GUIDelete($Passform)
                                    ExitLoop
                                Case $cancel
                                    GUIDelete($Passform)
                                    ExitLoop
                                Case $OK 
                                                                                                                                              msgbox(0,0, "Pressed OK")

    EndSwitch
                    WEnd
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks, here the basic form. I basically want to be able type in the fields and just hit enter with OK being the default focus.

$Passform = GUICreate($AppName, 315, 200)
                        GUISetStyle($WS_CAPTION, 0)
                        $Password = GUICtrlCreateInput("", 29, 48, 257, 21, $ES_PASSWORD)
                        $Confirm = GUICtrlCreateInput("", 29, 102, 257, 21, $ES_PASSWORD)
                        $passlab = GUICtrlCreateLabel("Enter New Password", 32, 24, 103, 17)
                        $conflab = GUICtrlCreateLabel("Confirm New Password", 32, 85, 113, 17)
                        $OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, 0)
                        $cancel = GUICtrlCreateButton("Cancel", 183, 164, 105, 25, 0)
                        GUISetState(@SW_SHOW)
While 1
                            $nMsg = GUIGetMsg()
                            Switch $nMsg
                                Case $GUI_EVENT_CLOSE
                                    GUIDelete($Passform)
                                    ExitLoop
                                Case $cancel
                                    GUIDelete($Passform)
                                    ExitLoop
                                Case $OK    
msgbox(0,0, "Pressed OK")

    EndSwitch
                    WEnd
Wow. You didn't try very hard. All I had to do was make it runnable (which should have already been done) and add $BS_DEFPUSHBUTTON (which was already suggested).

:D

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

$AppName = "Test"
$Passform = GUICreate($AppName, 315, 200)
GUISetStyle($WS_CAPTION, 0)
$Password = GUICtrlCreateInput("", 29, 48, 257, 21, $ES_PASSWORD)
$Confirm = GUICtrlCreateInput("", 29, 102, 257, 21, $ES_PASSWORD)
$passlab = GUICtrlCreateLabel("Enter New Password", 32, 24, 103, 17)
$conflab = GUICtrlCreateLabel("Confirm New Password", 32, 85, 113, 17)
$OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, $BS_DEFPUSHBUTTON)
$cancel = GUICtrlCreateButton("Cancel", 183, 164, 105, 25, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($Passform)
            ExitLoop
        Case $cancel
            GUIDelete($Passform)
            ExitLoop
        Case $OK
            MsgBox(64, "OK", "Password = " & GUICtrlRead($Password) & @CRLF & _
                    "Confirmation = " & GUICtrlRead($Confirm))
    EndSwitch
WEnd
Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Wow. You didn't try very hard. All I had to do was make it runnable (which should have already been done) and add $BS_DEFPUSHBUTTON (which was already suggested).

:D

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

$AppName = "Test"
$Passform = GUICreate($AppName, 315, 200)
GUISetStyle($WS_CAPTION, 0)
$Password = GUICtrlCreateInput("", 29, 48, 257, 21, $ES_PASSWORD)
$Confirm = GUICtrlCreateInput("", 29, 102, 257, 21, $ES_PASSWORD)
$passlab = GUICtrlCreateLabel("Enter New Password", 32, 24, 103, 17)
$conflab = GUICtrlCreateLabel("Confirm New Password", 32, 85, 113, 17)
$OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, $BS_DEFPUSHBUTTON)
$cancel = GUICtrlCreateButton("Cancel", 183, 164, 105, 25, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($Passform)
            ExitLoop
        Case $cancel
            GUIDelete($Passform)
            ExitLoop
        Case $OK
            MsgBox(64, "OK", "Password = " & GUICtrlRead($Password) & @CRLF & _
                    "Confirmation = " & GUICtrlRead($Confirm))
    EndSwitch
WEnd
Funny, I've done way more complex scripts and get stumped on a style. :o I did try many times and it didn't work, but because of your help I see why it did not. I added the $BS_DEFPUSHBUTTON after the 0 which you can see the 0 in my code before you changed it.

$OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, 0, $BS_DEFPUSHBUTTON)

When removed the zero as you have it like this $OK = GUICtrlCreateButton("OK", 29, 164, 105, 25, $BS_DEFPUSHBUTTON), it works correctly now.

Thanks


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
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
Sign in to follow this  
Followers 0