Alternative key to work after Menu Show Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Alternative key to work after Menu Show

15 May 2019, 13:55

Is there a way to allow for an alternative key to trigger an entry in a menu created with Menu Show? The following code does not, as I hoped, allow the CapsLock key to trigger the same choice as the hotkey c, since the hotkey reassignment doesn't work while the menu is shown.

Code: Select all

Menu, TopMenu, Add, &Caps lock choice, ChoiceForCapsLock
Menu, TopMenu, Add, &Some other function, SomethingElse

^m::
	Hotkey, CapsLock, ChoiceForCapsLock	; temporarily; will be reset as soon as possible
	Menu, TopMenu, Show  
	Hotkey, CapsLock, Off	; resetting temporary assignment
	Return

ChoiceForCapsLock:
	MsgBox Caps lock choice
	Return

SomethingElse:
	MsgBox SomethingElse
	Return
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Alternative key to work after Menu Show  Topic is solved

16 May 2019, 02:28

Hallo,
try:

Code: Select all

Menu, TopMenu, Add, &Caps lock choice, ChoiceForCapsLock
Menu, TopMenu, Add, &Some other function, SomethingElse
^m::
	FileDelete, ~.ahk
    FileAppend, #NoTrayIcon`nInput`,Key`,VL1`nSend`,s`nExitApp`nCapslock::c, ~.ahk
    Run, ~.ahk
	Menu, TopMenu, Show
	Return

ChoiceForCapsLock:
	MsgBox Caps lock choice
	Return

SomethingElse:
	MsgBox SomethingElse
	Return
C or Capslock trigger "ChoiceForCapsLock"
All other alphanumerics "SomethingElse"
I hope somebody finds a better way!
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: Alternative key to work after Menu Show

16 May 2019, 12:27

Thanks - that's what I've been looking for. It contains two great ideas: (1) Using the Input function to ensure that the assignment lasts just as long as needed. (2) exiting a whole script to end the temporary assignment.

What's the "Send s" command for? I assume it's just left over from testing; I took it out and now it works like a charm.

You wrote "I hope somebody finds a better way!", presumably because you didn't like that the file system is involved. One can reduce that by not deleting and rewriting the satellite file each time the menu is called. That may still have a little performance impact, but that doesn't matter here since it's only done once directly for a user input.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Lamron750 and 240 guests