Jump to content


Photo

Ahk_L: Menu Item Functions for labels


  • Please log in to reply
2 replies to this topic

#1 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 21 July 2012 - 02:02 PM

Hi guys and Lexikos :p

I think this has been brought up by others before but here is it anyway... Okay bear with me, this is easier to explain in visual form.

Okay I think there should be a function option for menu items. Currently you can do this:
Menu, Tray, Add, Item 1, Items
Menu, Tray, Add, Item 2, Items
Menu, Tray, Add, Item 3, Items
Return

Items:
    Function(A_ThisMenuItem)
Return

Function(MenuName) {
    [color=#BF0000]... Some Commands[/color]
}
But I think you should be able to do this:

Note the lack of '%' (Percent sign) in front of 'Function()' so that it doesn't look for a Return value from the function when it is called. Instead another sign should be used to indicate a one way function such as '$' (dollar sign).
Menu, Tray, Add, Item 1, Items, [color=#BF0000]$ Function(A_ThisMenuName, A_ThisMenuItem)[/color]
Menu, Tray, Add, Item 1, [color=#BF0000]$ Function(A_ThisMenuName, A_ThisMenuItem)[/color]
Menu, Tray, Add, Item 2, [color=#BF0000]$ Function(A_ThisMenuName, A_ThisMenuItem)[/color]
Return

Function(MenuName,MenuItem) {
    [color=#BF0000]... Some Commands[/color]
}

I hope that makes sense otherwise I will clarify if requested. :)

#2 fragman

fragman
  • Members
  • 1591 posts

Posted 23 July 2012 - 08:52 PM

The function name itself should be enough, the function can optionally receive those parameters if it declares them. Also I would get rid of the $ character and instead call the function directly if no label of this name exists. This should not cause errors which weren't there before (Invalid label->Wrong function called).

#3 rbrtryn

rbrtryn
  • Members
  • 798 posts

Posted 23 July 2012 - 10:09 PM

Rather than use A_ThisMenuName, A_ThisMenuItem as function arguments you could combine them and use them as the name of the function, see here.

Or you can use a table lookup, like I did for GUI controls in this script.