Page 1 of 1

GuiControl, Focus

Posted: 08 Oct 2017, 05:40
by just me
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.

Re: GuiControl, Focus

Posted: 10 Oct 2017, 19:56
by Delta Pythagorean
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

Re: GuiControl, Focus

Posted: 26 Nov 2017, 03:18
by lexikos
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.

Re: GuiControl, Focus

Posted: 26 Nov 2017, 04:29
by just me
Thanks, v2 would be sufficient, at least for me.