Code: Select all
I_Icon = C:\AutoHotkey.ico
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon%
;return
Code: Select all
C:\AutoHotkey OFF.ico
Code: Select all
I_Icon = C:\AutoHotkey.ico
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon%
;return
Code: Select all
C:\AutoHotkey OFF.ico
Code: Select all
Menu, Tray, Icon, C:\AutoHotkey.ico
Menu, Tray, Icon, C:\AutoHotkey OFF.ico
Pause, On
Menu, Tray, Icon, C:\AutoHotkey.ico
Pause, Off
Code: Select all
Menu, Tray, Icon, C:\AutoHotkey.ico
Menu, tray, NoStandard ; removes edit, pause, reload etc
; other menu options
Menu, tray, Add, &Suspend Hotkeys , MenuHandler
Menu, tray, Icon,&Suspend Hotkeys , %A_AhkPath%, 3 ; default suspend icon
Menu, tray, Add, &Pause Script , MenuHandler
Menu, tray, Icon,&Pause Script , %A_AhkPath%, 4 ; default pause icon
MenuHandler:
;
If (A_ThisMenuItem = "&Pause Script")
{
Menu, Tray, Icon, C:\AutoHotkey OFF.ico
Pause
Return
}
very basic code you need to expand to turn it on/off
Code: Select all
#NoTrayIcon
hIconNormal := LoadPicture(A_AHKPath, "Icon1", IMAGE_ICON := 1)
hIconPaused := LoadPicture("Shell32", "Icon145", IMAGE_ICON := 1)
TrayIconActions("add", hIconNormal)
OnMessage(0x111, Func("WM_COMMAND").Bind(hIconNormal, hIconPaused))
Return
WM_COMMAND(hIconNormal, hIconPaused, wp, lp) {
static trayMenuPauseID := 65306, windowMenuPauseID := 65403
menuID := wp & 0xFFFF
if (menuID = trayMenuPauseID || menuID = windowMenuPauseID)
TrayIconActions("modify", A_IsPaused ? hIconNormal : hIconPaused)
}
TrayIconActions(command := "delete", hIcon := "", hWnd := "", uID := 0x404, nMsg := 0x404)
{
static NIF_MESSAGE := 1, NIF_ICON := 2, NIF_TIP := 4
, NIM_ADD := 0, NIM_MODIFY := 1, NIM_DELETE := 2
, _ := OnExit("TrayIconActions")
(hWnd = "" && hWnd := A_ScriptHwnd)
uFlags := (command = "add" ? NIF_MESSAGE|NIF_TIP : 0) | (command != "delete" ? NIF_ICON : 0)
action := command = "add" ? NIM_ADD : command = "modify" ? NIM_MODIFY : NIM_DELETE
VarSetCapacity(NOTIFYICONDATA, A_PtrSize*4 + 136, 0)
NumPut(size, NOTIFYICONDATA, "UInt")
NumPut(hWnd, NOTIFYICONDATA, A_PtrSize)
NumPut(uID, NOTIFYICONDATA, A_PtrSize*2)
if (command = "add") {
NumPut(nMsg, NOTIFYICONDATA, A_PtrSize*2 + 8, "UInt")
StrPut(A_ScriptName, &NOTIFYICONDATA + A_PtrSize*4 + 8, "CP0")
}
if (command != "delete") {
NumPut(uFlags, NOTIFYICONDATA, A_PtrSize*2 + 4, "UInt")
NumPut(hIcon, NOTIFYICONDATA, A_PtrSize*3 + 8)
}
DllCall("shell32\Shell_NotifyIcon", "UInt", action, "Ptr", &NOTIFYICONDATA)
}
Code: Select all
OnMessage(0x111, "WM_COMMAND")
WM_COMMAND(wp) {
static trayMenuPauseID := 65306, windowMenuPauseID := 65403
menuID := wp & 0xFFFF
if (wp >> 16 = 0) && (menuID = trayMenuPauseID || menuID = windowMenuPauseID)
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "Shell32", % A_IsPaused ? 1 : 145, 1
}
Code: Select all
;Home Icons
global HEnabledIcon = ParentPath . "HomeIcon.ico"
global HDisabledIcon = ParentPath . "HomeIconD.ico"
global UnknownIcon = ParentPath . "Unknown.ico"
global UnknownDisabledIcon := ParentPath . "UnknownDisabled.ico"
global GamingEnabledIcon := ParentPath . "GamingOn.ico"
global GamingDisabledIcon := ParentPath . "GamingOff.ico"
global MusicEnabledIcon := ParentPath . "MusicIcon.ico"
global MusicDisabledIcon := ParentPath . "MusicIconD.ico"
global MinimalistEnabledIcon := ParentPath . "MinimalistIcon.png"
global MinimalistDisabledIcon := ParentPath . "MinimalistDisabledIcon.png"
...
;Set the icon image
Menu,Tray,Icon, %UnknownIcon%
Code: Select all
;------------------------CHECK STATUS-------------------------
CheckStates()
{
CapsOn := GetKeyState("CapsLock", "T")
NumOn := GetKeyState("NumLock", "T")
If PauseFlag = 1 ;If the script is disabled
{
IconChoice = 1
;Menu,Tray,Icon, %DisabledIcon%
}
Else If PauseFlag = 0 ;If the script is active:
{
;Then check if the keyboard or mouse is disabled
;Is the keyboard disabled?
If DisableKeyboardFlag = 0
{
IconChoice = 3
;Menu,Tray,Icon, %KeyboardDisabledIcon%
}
;Is the mouse disabled?
Else If TouchToggle = 0
{
IconChoice = 5
;Menu,Tray,Icon, %MouseDisabledIcon%
}
;If the keyboard and mouse are active, check for all the different key combos
Else
{
If (CapsOn = 1 AND NumOn = 1)
{
IconChoice = 6
;Menu,Tray,Icon, %CapsNumLockWarningIcon%
}
Else If (CapsOn = 1 AND NumOn = 0)
{
IconChoice = 7
;Menu,Tray,Icon, %CapsWarningIcon%
}
Else If (CapsOn = 0 AND NumOn = 1)
{
IconChoice = 8
;Menu,Tray,Icon, %NumLockWarningIcon%
}
Else ;If all the keys are off, it's the standard icon
{
IconChoice = 2
}
}
}
;msgbox IconChoice = %IconChoice%
;Once you know the state, pick the icon.
Switch IconChoice
{
Case 0:
msgbox Test
Case 1:
Menu,Tray,Icon, %DisabledIcon%
Case 2: ;to do more than one case at a time use Case 2, 3:
Menu,Tray,Icon, %EnabledIcon%
Case 3:
Menu,Tray,Icon, %KeyboardDisabledIcon%
Case 4:
Menu,Tray,Icon, %EnabledIcon%
Case 5:
Menu,Tray,Icon, %MouseDisabledIcon%
Case 6:
Menu,Tray,Icon, %CapsNumLockWarningIcon%
Case 7:
Menu,Tray,Icon, %CapsWarningIcon%
Case 8:
Menu,Tray,Icon, %NumLockWarningIcon%
Default:
msgbox IconChoice doesn't match icons!
}
}
Return
;-------------------------------------------------------------
I have a different modus operandi for thatsubmeg wrote: ↑06 Jun 2022, 07:26I have quite a few icons that I switch between; I have different "profiles" for my code, as I have a single main script that I use, but depending on which machine I am working on, file paths can be different and so I need to update them without having to change my code, so I just switch profile instead.
[...]
I am having trouble adapting this to my needs, as with this change it does not workt:teadrinker wrote: ↑06 Jun 2022, 07:11Or like this:Code: Select all
OnMessage(0x111, "WM_COMMAND") WM_COMMAND(wp) { static trayMenuPauseID := 65306, windowMenuPauseID := 65403 menuID := wp & 0xFFFF if (menuID = trayMenuPauseID || menuID = windowMenuPauseID) Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "Shell32", % A_IsPaused ? 1 : 145, 1 }
Code: Select all
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "C:\AutoHotkey.ico", % A_IsPaused ? "C:\AutoHotkey OFF.ico"
Code: Select all
WM_COMMAND(wp) {
static trayMenuPauseID := 65306, windowMenuPauseID := 65403
menuID := wp & 0xFFFF
if (wp >> 16 = 0) && (menuID = trayMenuPauseID || menuID = windowMenuPauseID)
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "C:\AutoHotkey.ico",, 1
}
This does not work
Yes I did; just like in case of my other code where I apparently had success in understanding the help files [viewtopic.php?f=76&t=104768&p=466452#p466452]. So that mine above was what I came up in this caseteadrinker wrote: ↑07 Jun 2022, 06:39Have you tried reading the docs to understand what each parameter means?
My example must work. Show your complete code. But try this as a separate script first:
Code: Select all
OnMessage(0x111, "WM_COMMAND")
WM_COMMAND(wp) {
static trayMenuPauseID := 65306, windowMenuPauseID := 65403
menuID := wp & 0xFFFF
if (wp >> 16 = 0) && (menuID = trayMenuPauseID || menuID = windowMenuPauseID)
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "C:\AutoHotkey.ico",, 1
}
Sorry, I am on medication that simply makes me dumb - and I have too many threads on this form trying to resolve many AHK issues, thus sitting on them at night. So yes- it works. And the title of this topic should have been "How to change tray icons to custom ones when the script is if for example paused?"
Code: Select all
A_IsSuspendedmenuID
Code: Select all
A_IsNormalmenuID
Code: Select all
OnMessage(0x111, "WM_COMMAND")
WM_COMMAND(wp) {
if (wp >> 16 = 0) {
MsgBox % wp & 0xFFFF
Return false
}
}
Esc:: ExitApp
I got meselfteadrinker wrote: ↑07 Jun 2022, 16:09Launch this script:
[...]
then open the tray menu of the script and click a menu item.
I've edited the script, now it shouldn't close.
There is no separate value for un-Pause since it's the same menu item.Keymaker wrote:the value for un-Pause [AKA the normal state] in unobtainable, as the script does not really pause
Code: Select all
OnMessage(0x111, "WM_COMMAND")
WM_COMMAND(wp) {
static trayMenuPauseID := 65306, windowMenuPauseID := 65403
menuID := wp & 0xFFFF
if (wp >> 16 = 0) && (menuID = trayMenuPauseID || menuID = windowMenuPauseID)
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "C:\AutoHotkey PAUSE.ico",, 1
}
OnMessage(0x111, "WM_COMMAND")
WM_COMMAND(wp) {
static trayMenuSuspendHotkeysID := 65305, windowMenuSuspendHotkeysID := 65403
menuID := wp & 0xFFFF
if (wp >> 16 = 0) && (menuID = trayMenuSuspendHotkeysID || menuID = windowMenuSuspendHotkeysID)
Menu, Tray, Icon, % A_IsPaused ? A_AHKPath : "C:\AutoHotkey SUSPEND.ico",, 1
}
I did not even imagined that this could be possible. So I will ask right away: does this also have a double state - one when first the script was suspended and then paused and other when first the script was paused and only then suspended?teadrinker wrote: ↑08 Jun 2022, 12:44[...]
What icon should be if the script is paused and suspended at the same time?
Why not? You can set the check mark on both items in the tray menu, one by one. And you will see, how the script icon changes (I mean an unmodified script).
No, there is no difference. If the script is paused but unsuspended you can still use its hotkeys:
Code: Select all
i := 0
Pause
$F1::
Loop {
ToolTip % ++i
Sleep, 100
}
Return
Code: Select all
Icons := { 0: {path: A_AHKPath, iconNumber: 1, status: "normal"}
, 1: {path: "C:\AutoHotkey Icons\AH icon #1.ico", iconNumber: "", status: "paused"}
, 2: {path: "C:\AutoHotkey Icons\AH icon #2.ico", iconNumber: "", status: "suspended"}
, 3: {path: "C:\AutoHotkey Icons\AH icon #3.ico", iconNumber: "", status: "paususp"} }
OnMessage(0x111, Func("WM_COMMAND").Bind(Icons))
WM_COMMAND(Icons, wp) {
static menuIDs := { 65305: {action: "suspend", value: 2}
, 65306: {action: "pause" , value: 1}
, 65403: {action: "pause" , value: 1}
, 65404: {action: "suspend", value: 2} }
menuID := wp & 0xFFFF
if (wp >> 16 = 0 && inputStatus := menuIDs[menuID, "value"]) {
prevStatus := A_IsSuspended << 1|A_IsPaused
newSataus := prevStatus ^ inputStatus
Menu, Tray, Icon, % Icons[newSataus, "path"], % Icons[newSataus, "iconNumber"], 1
}
}
I'm not quite get what you mean by that. What the menu should look like?
Users browsing this forum: apeironn, Google [Bot], madensuyu1, peter_ahk and 339 guests