Jump to content

Set focus of a button


Recommended Posts

I'm trying to figure out how to have an input field to type in and have a button as the focus. So when I type I can hit enter and it excutes the button function.

I tried looking at _GUICtrlButton_SetFocus but can't seem to get that to work. Anyone?

Edited by EndFunc
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Maybe this button style will work for you:

#include <ButtonConstants.au3>
$Button_Find = GUICtrlCreateButton("FIND PATIENT", 400, 33, 96, 43, $BS_DEFPUSHBUTTON)
That's cool, but still don't know how to make that work with an input field. I have the button physically next to the input field. Now, I'm trying to get it to be the focus so I can just hit enter but when using this style it doesn't set the focus. I must be doing something wrong. :P
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

That's cool, but still don't know how to make that work with an input field. I have the button physically next to the input field. Now, I'm trying to get it to be the focus so I can just hit enter but when using this style it doesn't set the focus. I must be doing something wrong. :P

Tried this and it wasn't very effective except once. Is there some sort of event handler that checks if you type anything in to the input it sets focus to the button. That sounds like what the style does but doesn't seem to work.

$CheckID = GUICtrlCreateButton("Validate", 426, 140, 85, 21, 0)

GUICtrlSetState($CheckID, $GUI_FOCUS)

Edited by EndFunc
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Is this the behavior you're after?

#include <GUIConstants.au3>
#include <ButtonConstants.au3>

    GUICreate("", 240, 80)
    $Input = GUICtrlCreateInput("", 20, 20, 120, 20)
    $Button = GUICtrlCreateButton("Button", 180, 20, 50, 20, $BS_DEFPUSHBUTTON)
    GUISetState()   

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button
                MsgBox(0, 'Testing', 'Button pressed')
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
Link to comment
Share on other sites

a bit off topic's title, but this is what you want, it detects ENTER on the input:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>

Global Const $VK_RETURN = 0x0D ;Enter key
Global Const $GWL_WNDPROC = -4

$Form1 = GUICreate("Form1", 320, 30)
$Input1 = GUICtrlCreateInput("", 5, 5, 210, 20)
$Button1 = GUICtrlCreateButton("Button1", 220, 5, 95, 20)
GUISetState(@SW_SHOW)

Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
Global $wProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), $GWL_WNDPROC, $wProc)
            DllCallbackFree($wProcHandle)
            Exit
        Case $Button1
            _some_action()
    EndSwitch
WEnd

func _some_action()
    TrayTip("", GUICtrlRead($Input1), 10)
EndFunc

Func _WindowProc($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $hWnd
        case GUICtrlGetHandle($Input1)
            Switch $iMsg
                Case $WM_GETDLGCODE
                    Switch $wParam
                        Case $VK_RETURN
                            _some_action() ;or use:
;~                          ControlClick($Form1, "", $Button1) ;but this will make you loose focus on the input
                    EndSwitch
            EndSwitch
    EndSwitch
    Return _WinAPI_CallWindowProc($wProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc
Edited by sandin
Link to comment
Share on other sites

maybe... uhh i dont know if sandin's post does what you want, but i always use

opt('guioneventmode',1)
Guictrlsetonevent($Input,'Button_ok')

it works fine for me UNLESS the input you have is a style that messes with the lines, i dont know why, but ^ that :S

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