Jump to content

Using Enter Key to shift focus to OK button from Input Box


Ealric
 Share

Recommended Posts

Using a child GUI window with specific input boxes. The behavior I want to set is so that as a person types inside the input box, upon hitting enter key the focus shifts to the OK button (which is semi-default for a form behavior effect).

I've tried using hotkeyset but unfortunately you can't send parameters to a function with hotkeyset. So, is there anything usable to do this with? As always, thanks in advance.

$cGUI = GUICreate("  Child GUI Window", 340, 220, -1, -1, -1, $WS_EX_TOOLWINDOW, $window)
$inputbox = GUICtrlCreateInput("Input Box", 10, 70, 120, 20)
$OKc = GUICtrlCreateButton("&OK", 20, 120, 100, 20)
Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

$GUI_FOCUS?

That doesn't work. I don't have a working example as to how to focus from an enter key without using a function to do so.

GuiCtrlSetState($OKc, $GUI_FOCUS) for instance allows you to set the state to focus onto the OK button. But, how do you apply that from the enter key? That's the issue. Whenever someone hits the enter key it needs to force this state but I can't see how to do that without using a custom UDF or using HotKeySet which won't allow you to pass the Control to the function.

So, no that won't work. Anyone else understand what I'm asking here?

The closest I've come to is:

Func _checkfocus($GUI,$cID,$okB) ; Gui Name, Control Name to check focus, OK button name
    If _IsFocused($GUI, $cID) Then
        Sleep(020)
        HotKeySet("{ENTER}", "EntPress")
    Else
        HotKeySet("{ENTER}")
    EndIf
EndFunc

Func EntPress()
    ;GUICtrlSetState($okB,$GUI_FOCUS)
    send("{TAB}")
    Send("{ENTER}")
EndFunc

Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc

But EntPress only creates about 1,000 jitters of going back and forth between the focus and the control.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

Using a child GUI window with specific input boxes. The behavior I want to set is so that as a person types inside the input box, upon hitting enter key the focus shifts to the OK button (which is semi-default for a form behavior effect).

I've tried using hotkeyset but unfortunately you can't send parameters to a function with hotkeyset. So, is there anything usable to do this with? As always, thanks in advance.

$cGUI = GUICreate("  Child GUI Window", 340, 220, -1, -1, -1, $WS_EX_TOOLWINDOW, $window)
$inputbox = GUICtrlCreateInput("Input Box", 10, 70, 120, 20)
$OKc = GUICtrlCreateButton("&OK", 20, 120, 100, 20)
Sounds like you want $BS_DEFPUSHBUTTON on your button, like this

#include <GUIConstants.au3>
$cGUI = GUICreate("  Child GUI Window", 340, 220, -1, -1, -1, $WS_EX_TOOLWINDOW)
$inputbox = GUICtrlCreateInput("Input Box", 10, 70, 120, 20)
$OKc = GUICtrlCreateButton("&OK", 20, 120, 100, 20, $BS_DEFPUSHBUTTON)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $OKc
            MsgBox(0, "", "Button fired")
    EndSelect
WEnd
Link to comment
Share on other sites

Sounds like you want $BS_DEFPUSHBUTTON on your button, like this

#include <GUIConstants.au3>
$cGUI = GUICreate("  Child GUI Window", 340, 220, -1, -1, -1, $WS_EX_TOOLWINDOW)
$inputbox = GUICtrlCreateInput("Input Box", 10, 70, 120, 20)
$OKc = GUICtrlCreateButton("&OK", 20, 120, 100, 20, $BS_DEFPUSHBUTTON)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $OKc
            MsgBox(0, "", "Button fired")
    EndSelect
WEnd
I'll try that out now. Thanks.

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

Thanks mate. This is exactly what I needed. And, if I need to apply focus back to the inputbox I'll just use ControlFocus. Thanks again!

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

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