GuiControl, Focus

Report problems with documented functionality
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

GuiControl, Focus

08 Oct 2017, 05:40

Button wrote:The example above includes the word Default in its Options to make "OK" the default button. The default button's action is automatically triggered whenever the user presses ENTER, except when the keyboard focus is on a different button ...
That's not true if you switch the keyboard focus to another button using GuiControl, Focus.

Code: Select all

#NoEnv
Gui, Margin, 20, 20
Gui, Add, Text, , Press ENTER to trigger the focused button.
Gui, Add, Button, wp Default vBtnD gDefaultButton, Default
Gui, Add, Button, wp vBtnF gFocusedButton, Focused
GuiControl, Focus, BtnF
Gui, Show, , Test
Return

GuiClose:
ExitApp

DefaultButton:
FocusedButton:
MsgBox, %A_ThisLabel% was triggered!
Return
This seems to be related to How to set focus in a dialog box and should be fixed, at least in v2.

Edit: Updated the OldNewThing link.
Last edited by just me on 20 Jun 2021, 08:45, edited 1 time in total.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: GuiControl, Focus

10 Oct 2017, 19:56

I think it has more to do with *how* the button was clicked/focused. For example controlling the button via Tab I.E Tabstops, would focus the button via Tab. However if you click on the button it has a different "effect." This has happened to me before but just to be sure, I'd suggest to see if ControlGet instead of GuiControlGet would do anything different. I don't know as of right now, I'm too lazy to check :P

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: GuiControl, Focus

26 Nov 2017, 03:18

I'm not inclined to change the behaviour in v1, especially because WM_NEXTDLGCTL "automatically selects the text of an edit control (if the target window is an edit control)".

It needs to be used with Edit controls, otherwise a previously focused Button can have the highlight even though pressing Enter while a single-line Edit control is active will activate the real default button.
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GuiControl, Focus

26 Nov 2017, 04:29

Thanks, v2 would be sufficient, at least for me.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 20 guests