Set focus to a GUI button on load

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nhanderr
Posts: 9
Joined: 21 Jun 2022, 18:19

Set focus to a GUI button on load

Post by nhanderr » 05 Jul 2022, 10:17

Hi all,

I have a GUI that when I load I want a certain button to be highlighted by default, so the user can quickly hit enter instead of having to mouse over.

Code: Select all

GuiHWND := WinExist() 								
	Gui, add, ListBox, h600 w200 vLB gPopulate, % persons
	Gui, add, Edit, x+10 hp w600 vtextbox ReadOnly
	Gui, add, Button, x722 y605 w100 h25 gselect, Select
	Gui, add, Button, x9 y605 w100 h25 gcancel, Cancel
	Gui, show
	Gui, -SysMenu
	gosub, Populate
	clipboard := clipsave
	ClipWait 0.2
	return
I've just included a chunk of it for brevity's sake but the button that I'm trying to set focus to is gselect. Can anyone help with this?


BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Set focus to a GUI button on load

Post by BoBo » 05 Jul 2022, 10:25

Well, it's the second sentence in AHK's Help about Buttons:
For example:

Gui, Add, Button, Default w80, OK
Appearance:

Button
The example above includes the word Default in its Options to make "OK" the default button.
TBH, not that hard to find. :eh:

Post Reply

Return to “Ask for Help (v1)”