GuiControl, Focus

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

GuiControl, Focus

Post by just me » 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

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


MsgBox, %A_ThisLabel% was triggered!
This seems to be related to How to set focus in a dialog box and should be fixed, at least in v2.
User avatar
Delta Pythagorean
Posts: 420
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: GuiControl, Focus

Post by Delta Pythagorean » 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
Posts: 6175
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: GuiControl, Focus

Post by lexikos » 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: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GuiControl, Focus

Post by just me » 26 Nov 2017, 04:29

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

Return to “Bug Reports”