Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik Menu

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik Menu

11 May 2015, 04:55

Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch, rather set focus !

Like Menus

A gui with 40 buttons, when you press an alphabet, if there is only single entry it should run button.
If there is more than one button starting with letter "s", the focus should shift to S, but not launch the first button.

is it possible ?

Thanks in advance for your help and support.
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik

14 May 2015, 10:00

If nobody replied it may be because other people are as confused by the question as I am. The way all good GUIs are designed is that they assign shortcut keys to their buttons, which don't necessarily have to be the initial of the button, to avoid that problem. If there are still any duplicates left, then there's still a way to address them with keys. E.g. under Windows the standard for that is to repeat entering the same key until the correct button (or other control, as the case may be) is selected, and then send space to select that one. Does that answer your question?
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik

15 May 2015, 02:12

Thanks for your time!

I tried this but it does not go to second button if i press it 2 OR more than 2 times.

Can you show me a way designing a GUI where if i press a key example N, and if there is more than 1 button whose name starts with N then, after pressing more than 1 time it should go to next button and as follows.

Thanks

Code: Select all

Gui, Add, Button, G1, Nothing
Gui, Add, Button, G2, Nothing
Gui, Add, Button, G3, Nothing
Gui, Add, Button, G4, Nothing
Gui, Add, Button, G5, Nothing
Gui, Show
return

1:
MsgBox 1
return

2:
MsgBox 2
return

3:
MsgBox 3
return

4:
MsgBox 4
return

5:
MsgBox 5
return

Micromegas wrote:If nobody replied it may be because other people are as confused by the question as I am. The way all good GUIs are designed is that they assign shortcut keys to their buttons, which don't necessarily have to be the initial of the button, to avoid that problem. If there are still any duplicates left, then there's still a way to address them with keys. E.g. under Windows the standard for that is to repeat entering the same key until the correct button (or other control, as the case may be) is selected, and then send space to select that one. Does that answer your question?
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik

17 May 2015, 00:36

Can't you just use an ampersand?
An ampersand (&) may be used in the name button to underline one of its letters. For example:

Code: Select all

Gui, Add, Button,, &Pause
In the example above, the letter P will be underlined, which allows the user to press Alt+P as shortcut key. To display a literal ampersand, specify two consecutive ampersands (&&).
hd0202
Posts: 183
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik

17 May 2015, 03:39

This is my suggestion:

Code: Select all

n_s = 1
n_t = 5
o_s = 6
o_t = 7
f = 1
Gui, Add, Button, G1 default, Nothing
Gui, Add, Button, G2, Nothing
Gui, Add, Button, G3, Nothing
Gui, Add, Button, G4, Nothing
Gui, Add, Button, G5, Nothing
Gui, Add, Button, G6, Other
Gui, Add, Button, G7, Other
Gui, Show
return

1:
MsgBox 1
return

2:
MsgBox 2
return

3:
MsgBox 3
return

4:
MsgBox 4
return

5:
MsgBox 5
return

6:
MsgBox 6
return

7:
MsgBox 7
return

n::
o::
guicontrolget, f, focus
stringreplace, f, f, button
;msgbox, % f
guicontrol, -default, Button%f%
thk := a_thishotkey
xs = %thk%_s 
xt = %thk%_t
x_s := %xs%
x_t := %xt%
;msgbox, % x_s " - " x_t
f++
if (f < x_s or f > x_t)
  f := x_s
guicontrol, +default, Button%f%
guicontrol, focus, Button%f%
return

exitapp
escape::exitapp
Hubert
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Gui with many buttons, when a key is pressed with same initial alphabet, it should not launch rather set focus,Lik

17 May 2015, 04:29

Truly Amazing, its working :clap:
Can i add more alphabets to

a::
b::
c:: AND SO ON...
n::
o::
x::
y::
z::
guicontrolget, f, focus


Thanks in advance for your help and support. :dance:
hd0202 wrote:This is my suggestion:

Code: Select all

n_s = 1
n_t = 5
o_s = 6
o_t = 7
f = 1
Gui, Add, Button, G1 default, Nothing
Gui, Add, Button, G2, Nothing
Gui, Add, Button, G3, Nothing
Gui, Add, Button, G4, Nothing
Gui, Add, Button, G5, Nothing
Gui, Add, Button, G6, Other
Gui, Add, Button, G7, Other
Gui, Show
return

1:
MsgBox 1
return

2:
MsgBox 2
return

3:
MsgBox 3
return

4:
MsgBox 4
return

5:
MsgBox 5
return

6:
MsgBox 6
return

7:
MsgBox 7
return

n::
o::
guicontrolget, f, focus
stringreplace, f, f, button
;msgbox, % f
guicontrol, -default, Button%f%
thk := a_thishotkey
xs = %thk%_s 
xt = %thk%_t
x_s := %xs%
x_t := %xt%
;msgbox, % x_s " - " x_t
f++
if (f < x_s or f > x_t)
  f := x_s
guicontrol, +default, Button%f%
guicontrol, focus, Button%f%
return

exitapp
escape::exitapp
Hubert

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 264 guests