Controls with shortcut keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Controls with shortcut keys

01 May 2019, 05:23

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
Last edited by newbieforever on 02 May 2019, 01:19, edited 3 times in total.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Controls with shortcut keys

01 May 2019, 05:35

For me it works (I think).

When I press F9, while the MsgBox is open a new gui button is being added.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: Controls with shortcut keys

01 May 2019, 06:07

WalkerOfTheDay, I edited my demo script to illustrate the problem better. The shortcut letter doesn't work if the MsgBox is displayed.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Controls with shortcut keys

01 May 2019, 06:14

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 ?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Controls with shortcut keys

02 May 2019, 01:30

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...
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: Controls with shortcut keys

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.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Controls with shortcut keys

02 May 2019, 04:07

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
Last edited by WalkerOfTheDay on 02 May 2019, 04:35, edited 1 time in total.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: Controls with shortcut keys

02 May 2019, 04:11

WalkerOfTheDay: Yes, not a perfect workaround, but it works...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Google [Bot], Nerafius, RandomBoy and 183 guests