Is it possible to determine inside the AHK_NOTIFYICON function if it was called due to a physical right-click on the icon or the hotkey sending the message?
Monitor the AHK_NOTIFYICON message to react when the user interacts with the tray icon. Send the message to simulate user interaction with the tray icon. When I first suggested it, I was not expecting you to use OnMessage, because I saw (and still see) no reason to override the default handling.
If you want one instance of the script to trigger some custom action in another instance of the same script, there is no need to use AHK_NOTIFYICON. It doesn't matter that what you are doing is related to the tray icon or tray menu. You can pick any unused or registered message number and send that between instances, or you can use any other method of inter-process communication.
That aside,
wParam should always equal AHK_NOTIFYICON (the ID of the tray icon) when the notification comes from the tray. When you send the message, wParam has whatever value you give it, or 0 if you omitted it. AutoHotkey ignores wParam, because it has only one tray icon.
; show context menu on right click - this should actually result in showing menu twice because system should automatically show it
AHK_NOTIFYICON is a custom message, with no system-defined meaning or handling.
AutoHotkey has
default handling of the message, which will be carried out if you do not return a number.