Page 1 of 1

Controls with shortcut keys

Posted: 01 May 2019, 05:23
by newbieforever
Hi!

The following demo script shows a gui with a button, for which a shortcut key (b) is set. If a MsgBox ist open, the shortcut key does not work, even if the gui is the active window (but clicking on button works).

Is there a way to make the shortcut key work even if there is a MsgBox?

Code: Select all

Gui New: Add, Button, ggButton, &Button
Gui New: Show, x100 y100 w100 h100, GuiNew

MsgBox MSGBOX

RETURN

gButton:
  ;WinActivate, GuiNew
  MsgBox BUTTON
Return
EDITED

Re: Controls with shortcut keys

Posted: 01 May 2019, 05:35
by WalkerOfTheDay
For me it works (I think).

When I press F9, while the MsgBox is open a new gui button is being added.

Re: Controls with shortcut keys

Posted: 01 May 2019, 06:07
by newbieforever
WalkerOfTheDay, I edited my demo script to illustrate the problem better. The shortcut letter doesn't work if the MsgBox is displayed.

Re: Controls with shortcut keys

Posted: 01 May 2019, 06:14
by WalkerOfTheDay
It's still not really clear to me what you are trying to accomplish in the demo script.

What do you mean by 'shortcut' letter ?

Re: Controls with shortcut keys

Posted: 02 May 2019, 01:30
by gregster
What do you mean by 'shortcut' letter ?
The & in &Button creates a shortcut (alt+b) for the button which, it seems, doesn't work while the msgbox is shown.

Compare:
https://www.autohotkey.com/docs/commands/Gui.htm#Navigate wrote:Certain controls may contain an ampersand (&) to create a keyboard shortcut, which might be displayed in the control's text as an underlined character (depending on system settings). A user activates the shortcut by holding down the Alt key then typing the corresponding character. For buttons, checkboxes, and radio buttons, pressing the shortcut is the same as clicking the control.[...]
Perhaps someone knows a trick to enable this shortcut while a regular msgbox is displayed (although that's probably not the point of a msgbox) - if not, perhaps build your own pseudo-msgbox with another GUI or use a regular AHK-hotkey for !b (perhaps context-specific: only when your GUI is active) to jump via gosub to the gButton label, if you really need this functionality while a msgbox is displayed...

Re: Controls with shortcut keys

Posted: 02 May 2019, 01:46
by newbieforever
Thank you, gregster. In the meantime I believe that there is no way (no trick). But there are workarounds, yes.

Re: Controls with shortcut keys

Posted: 02 May 2019, 04:07
by WalkerOfTheDay
newbieforever wrote:
02 May 2019, 01:46
Thank you, gregster. In the meantime I believe that there is no way (no trick). But there are workarounds, yes.
Does this work for you ?

Code: Select all


Gui New: Add, Button, ggButton, &Button
Gui New: Show, x100 y100 w100 h100, GuiNew

MsgBox MSGBOX

RETURN

gButton:
  ;WinActivate, GuiNew
  MsgBox BUTTON
Return

!b::
ControlClick, Button1,, Button
return

Re: Controls with shortcut keys

Posted: 02 May 2019, 04:11
by newbieforever
WalkerOfTheDay: Yes, not a perfect workaround, but it works...