Hi everyone,
i want to write a script that will notify me when i suspend the script with the "Suspend Hotkeys" item on the default menu. Is there a label for that item?
Are there labels for the default icon menu items? Topic is solved
Are there labels for the default icon menu items?
Last edited by necomerx on 03 Jul 2021, 21:34, edited 1 time in total.
Re: Are there labels for the default icon menu items?
It's a variable, not a label, but A_IsSuspended tells you if the script is suspended. So you can accomplish what you described like this:
Code: Select all
#Persistent
Notified := 0
SetTimer, SuspendCheck, 300
return
SuspendCheck:
if A_IsSuspended {
if !Notified {
Notified := 1
MsgBox, Script is suspended
}
}
else
Notified := 0
return
Re: Are there labels for the default icon menu items?
Thanks you boiler for clarifying and your help!
i'm gonna check that now!
Edit:
As i though It is not working unfortunately with my script witch has a loop, but it is working for a new script. So the default menu don't have variables to acces its different item, only possible for custom menu i guess?
https://autohotkey.com/board/topic/3955-menu-tray-default-help/
i'm gonna check that now!
Edit:
As i though It is not working unfortunately with my script witch has a loop, but it is working for a new script. So the default menu don't have variables to acces its different item, only possible for custom menu i guess?
https://autohotkey.com/board/topic/3955-menu-tray-default-help/
Re: Are there labels for the default icon menu items? Topic is solved
All menu items work by sending a WM_COMMAND message to one of the script's windows (usually the main window). User-created menu items have an auto-assigned ID that depends on the order in which items are created across all menus, so it is usually best to just stick with assigning labels/functions via the Menu command in v1.x or Menu object in v2.
The IDs of the standard menu items are defined in the source code. Tray menu items are defined by the CommandIDs enumeration, with ID_TRAY_SUSPEND being 65305. The main window's File menu items are defined in resource.h, with ID_FILE_SUSPEND being 65404.
To detect when the user selects a standard menu item, you can monitor the WM_COMMAND message (0x111).
The default action of Suspend Hotkeys is performed after the function returns, so A_IsSuspended is true if hotkeys were previously suspended but are about to be unsuspended. Alternatively, you can override (and in this case replicate) the default action:
With AutoHotkey v2.0, you can directly modify the standard menu items:
The correct term for "the default icon menu items" is "the standard menu items". They can be added to any menu with Menu MenuName, Standard or removed from the tray menu with Menu Tray, NoStandard. You can do the latter and then add your own custom menu items which look like the standard items but do whatever you want (and this also allows you to add icons with Menu Tray, Icon, ...).
The IDs of the standard menu items are defined in the source code. Tray menu items are defined by the CommandIDs enumeration, with ID_TRAY_SUSPEND being 65305. The main window's File menu items are defined in resource.h, with ID_FILE_SUSPEND being 65404.
To detect when the user selects a standard menu item, you can monitor the WM_COMMAND message (0x111).
Code: Select all
#Requires AutoHotkey v1.1
OnMessage(0x111, Func("Receive_WM_COMMAND"))
Receive_WM_COMMAND(wParam) {
if (wParam = 65305) { ; Tray, &Suspend Hotkeys
about_to_suspend := !A_IsSuspended
MsgBox % "Click OK to " (about_to_suspend ? "" : "un") "suspend hotkeys."
}
}
Code: Select all
#Requires AutoHotkey v1.1
OnMessage(0x111, Func("Receive_WM_COMMAND"))
Receive_WM_COMMAND(wParam) {
if (wParam = 65305) { ; Tray, &Suspend Hotkeys
Suspend
MsgBox % "Hotkeys " (A_IsSuspended ? "" : "un") "suspended."
return 0
}
}
Code: Select all
#Requires AutoHotkey v2.0-a138
A_TrayMenu.Add "&Suspend Hotkeys", TraySuspend
TraySuspend(*) {
Suspend
MsgBox "Hotkeys " (A_IsSuspended ? "" : "un") "suspended."
}
Persistent
The correct term for "the default icon menu items" is "the standard menu items". They can be added to any menu with Menu MenuName, Standard or removed from the tray menu with Menu Tray, NoStandard. You can do the latter and then add your own custom menu items which look like the standard items but do whatever you want (and this also allows you to add icons with Menu Tray, Icon, ...).
Re: Are there labels for the default icon menu items?
The approach lexikos showed is better, of course, but I'm not sure what you're saying about your script having a loop causing the approach I showed not to work. The timer continues regardless of whether your script is looping. For example:
Code: Select all
#Persistent
CoordMode, ToolTip, Screen
Notified := 0
SetTimer, SuspendCheck, 300
loop {
ToolTip, % "`n`tLoop count : " A_Index "`t`t `n ", A_ScreenWidth/2-100, A_ScreenHeight/2
Sleep, 100
}
return
SuspendCheck:
if A_IsSuspended {
if !Notified {
Notified := 1
TrayTip, Suspended, Script is suspended
}
}
else
Notified := 0
return
Re: Are there labels for the default icon menu items?
Thanks you lexikos also for clarifying and your great help! I was wondering for quite some times how it will be possible to interact with the standard menu items, and your detailed reply answer many of my questions! Your codes work well, also sorry boiler your code work fine in the auto-execute section of my script before the loop. I needed to specify that the codes will be integrated on a script i already have: it's a script with a loop to close some windows when they appears in the auto execute section then come some hotkeys. I do the mistake of putting your script after the auto execute section then when i put it after the loop it was obviously not working then i put it before and it works but my loop didn't work anymore, so i put it inside the loop and the two work fine. I already have a hotkey that create a gui to notify me when i suspend the script and i wanted to replicate the same thing when i click on "Suspend Hotkeys" on the menu. I make ajustment with your codes and lexikos's ones but the only problem i have is that when i unsuspend the script the gui is not destroyed (even thought it is destroyed with my hotkey), but i think that will be not hard to figure out,thanks. And by the way the tooltip gui with the shadow on your last script is gorgeous, didn't know that it was possible to have that kind of gui.
Re: Are there labels for the default icon menu items?
It sounds like you are not implementing it correctly in any of the scenarios you mentioned. It’s not correct to put it inside the loop, and both your script and this one would work if you put the correct part (not the entire script) before your loop. You apparently are putting the entire script in the auto-execute section. That is not correct.necomerx wrote: ↑ also sorry boiler your code work fine in the auto-execute section of my script before the loop. I needed to specify that the codes will be integrated on a script i already have: it's a script with a loop to close some windows when they appears in the auto execute section then come some hotkeys. I do the mistake of putting your script after the auto execute section then when i put it after the loop it was obviously not working then i put it before and it works but my loop didn't work anymore, so i put it inside the loop and the two work fine.
This is the only part you put in the auto-execute section, before the loop you already have in your script:
Code: Select all
Notified := 0
SetTimer, SuspendCheck, 300
This rest goes below your auto-execute section. To be safe, put this at the very bottom of your script:
Code: Select all
SuspendCheck:
if A_IsSuspended {
if !Notified {
Notified := 1
MsgBox, Script is suspended
}
}
else
Notified := 0
return
Again, it’s better to use lexikos’ approach. I’m just trying to show you how to properly implement a SetTimer routine into your scripts.
Re: Are there labels for the default icon menu items?
Yes i was integrating it wrong first when i put it after the auto execute section (i think i was so tired!). But when i put your code in the loop, i think i removed the Settimer, the label and the return lines, so it was working fine, but yes how you explain it is the proper way to do it and all is working fine. And yes lexikos' codes are high level, i just need some times to understand how i can integrate it with my lines of codes.
Last edited by necomerx on 04 Jul 2021, 06:23, edited 1 time in total.
Re: Are there labels for the default icon menu items?
The code from lexikos is just as easy to implement. The only line that goes in the auto-execute section (before your loop) is the OnMessage line. The rest is a function that goes below the auto-execute section. Again, just put it at the very bottom of your script. (You don’t need the #Requires line, but if you keep it, put it at the very top of the script.)
Re: Are there labels for the default icon menu items?
Yes thanks, the lexikos' code is integrated as you suggest and is working fine but with my gui, it is not working properly: when i suspend the script, the gui shows up fine but when i unsuspend it, it is not destroyed, here is the code :
Code: Select all
OnMessage(0x111, Func("Receive_WM_COMMAND"))
Receive_WM_COMMAND(wParam) {
if (wParam = 65305) { ; Tray, &Suspend Hotkeys
Suspend
gui, +AlwaysOnTop +Caption -MinimizeBox
gui, font, s10 , UD Digi Kyokasho NP-B
gui, add, text,, SUSPENDED
gui, Show
Loop
{
SetTimer, label2, 300000
label2:
gui, Flash
return
}
2GuiClose:
gui, Show
return
}
else
{
Gui, destroy
}
return
}
Re: Are there labels for the default icon menu items?
The Suspend menu item being selected again (to un-suspend) would not trigger the else part of your code. It’s the same menu item, so it would trigger the if part again.
Re: Are there labels for the default icon menu items?
Yep right and that's why i'm confused because i don't understand for the moment how i can make the code to work with my gui.
Re: Are there labels for the default icon menu items?
You would check the value of A_IsSuspended to know if that occurrence of the menu item selection was to suspend or un-suspend hotkeys, as lexikos demonstrated.
Re: Are there labels for the default icon menu items?
After many hours of trials, i finally manage to make it work properly, it can seems easy but this one was really tough for me. I could not keep your script boiler because of the timer, the gui was keeping the focus so it was difficult to work on other windows when the script was suspended. I still need to fully understand lexikos' code but i manage to make it work how i wanted. Here is the final code:
Thanks you very much for your helps boiler, lexikos. You rock !
Code: Select all
OnMessage(0x111, Func("Receive_WM_COMMAND"))
Receive_WM_COMMAND(wParam) {
if (wParam = 65305) { ; Tray, &Suspend Hotkeys
gui, +AlwaysOnTop +Caption -MinimizeBox
gui, font, s10 , UD Digi Kyokasho NP-B
gui, add, text,, SUSPENDED
if A_isSuspended
{
gui, destroy
return
}
Suspend
gui, Show,
Loop
{
SetTimer, label2, 300000
label2:
gui, Flash
return 0
}
2GuiClose:
gui, Show
return
}
}
Re: Are there labels for the default icon menu items?
One benefit of using functions is that they can be safely interspersed with other auto-execute code. There is no need to split the parts of my example; they can all be placed at the top of the script. Replacing your timer subroutine with a function would give it the same benefit. If someone then tries to place it inside another function with AutoHotkey v1, they will get a very strong hint that it isn't the right place. With AutoHotkey v2 it might work even there.
Re: Are there labels for the default icon menu items?
That’s a good point. It would make adding posted code to their scripts more foolproof. Thanks for the suggestion.
Re: Are there labels for the default icon menu items?
+1 boiler, thanks lexikos.
Who is online
Users browsing this forum: peter_ahk and 355 guests