%A_ThisMenuItem% needs to be fixed?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

%A_ThisMenuItem% needs to be fixed?

19 Sep 2017, 23:50

The document said,
To underline one of the letters in a menu item's name, precede that letter with an ampersand (&). When the menu is displayed, such an item can be selected by pressing the corresponding key on the keyboard.
The following code does exactly that, but the message coming out from %A_ThisMenuItem% is &MyItem1, My&Item2 and MyItem&3, rather than
MyItem1, MyItem2 and MyItem3. I don't think that's what we want. How can I fix this? Thanks.

Code: Select all

Menu, MyMenu, Add, &MyItem1, MenuHandler
Menu, MyMenu, Add, My&Item2, MenuHandler
Menu, MyMenu, Add, MyItem&3, MenuHandler
Menu, MyMenu, Show
return

MenuHandler:
MsgBox You selected "%A_ThisMenuItem%" from the menu %A_ThisMenu%.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 01:38

I don't think that's what we want
Well, I think that's what I want :thumbup:

Code: Select all

MenuHandler:
MsgBox % "You selected " StrReplace(A_ThisMenuItem,"&","") " from the menu " A_ThisMenu "."
Not tested.
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 02:28

Thanks for the reply, I just dont't know why one needs that & in &MyItem1, My&Item2 and MyItem&3? Do I miss anything here?
Last edited by eagerahk on 20 Sep 2017, 21:12, edited 3 times in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 02:43

eagerahk wrote:Thanks for the reply, I just dont't know why one needs that & in &MyItem1, My&Item2 and MyItem&3? Do I miss anything here?
You've posted the excerpt from AHK's help that exactly explains that 'keyboard shortcut'-feature.
You won't have to use it if you don't use the keyboard to trigger menu-items.

Correct me f I'm wrong.
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 03:07

The value of %A_ThisMenuItem% does not need to carry that &.
Last edited by eagerahk on 20 Sep 2017, 21:13, edited 1 time in total.
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 03:12

MenuItemName wrote:To underline one of the letters in a menu item's name, precede that letter with an ampersand (&). When the menu is displayed, such an item can be selected by pressing the corresponding key on the keyboard. To display a literal ampersand, specify two consecutive ampersands as in this example: Save && Exit

When referring to an existing menu or menu item, the name is not case sensitive but any ampersands must be included. For example: &Open

Source: Menu
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 03:22

Thanks, just me. If %A_ThisMenuItem% can drop one &.
Then in the case of My&Item2, the desired value of %A_ThisMenuItem% should be MyItem2.
In the case of Save && Exit, the desired value of %A_ThisMenuItem% should be Save & Exit.

So that each user does not have to do it.
Last edited by eagerahk on 20 Sep 2017, 21:14, edited 1 time in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 03:52

TBH, I don't understand why you get the idea that it's a problem at all, especially for those ~7.473.690.000 other people out there ("... that's what we want/each user ...")??? :yawn:
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 03:53

When referring to an existing menu or menu item, the name is not case sensitive but any ampersands must be included. For example: &Open
That's also true if you refer to A_ThisMenuItem.
eagerahk wrote:... , so that each user does not have to do it.
Why do you have to do it?
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: %A_ThisMenuItem% needs to be fixed?

20 Sep 2017, 04:08

Think of it this way, if you want to change something regarding a sub-menu you will use.

Code: Select all

Menu, MyMenu, Add, &AHK, MenuHandler
return

MenuHandler:
	Menu, MyMenu, Add, % A_ThisMenuItem, NewMenuHandler
return

NewMenuHandler:
	ExitApp
return

RButton::Menu, MyMenu, Show
Witch only works because the & are included.

Else you will get a new entry.

Code: Select all

Menu, MyMenu, Add, &AHK, NoAmpersand
return

NoAmpersand:
	Menu, MyMenu, Add, % StrReplace(A_ThisMenuItem, "&", ""), NewMenuHandler
return

NewMenuHandler:
	ExitApp
return

RButton::Menu, MyMenu, Show
Please excuse my spelling I am dyslexic.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Google [Bot], Joey5, lechat and 272 guests