Notify another script when I suspend a script using the tray icon Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Notify another script when I suspend a script using the tray icon

Post by AHKStudent » 27 Sep 2022, 09:40

Is there a way to send a message to another script when I suspend a script using the trey icon?

I know from the documentation that I could use one script to suspend another, however, in my case, I need to see at all times on the gui of another script if another script is suspended or not.

Any ideas?

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Notify another script when I suspend a script using the tray icon  Topic is solved

Post by mikeyww » 27 Sep 2022, 16:47

Hi,

You can replace the standard menu with a customized menu that suspends and notifies, or just notifies.

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Notify another script when I suspend a script using the tray icon

Post by AHKStudent » 27 Sep 2022, 17:04

mikeyww wrote:
27 Sep 2022, 16:47
Hi,

You can replace the standard menu with a customized menu that suspends and notifies, or just notifies.
thanks :thumbup: :thumbup:

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Notify another script when I suspend a script using the tray icon

Post by teadrinker » 27 Sep 2022, 18:40

Also you can intercept the command from the standard tray menu:

Code: Select all

OnMessage(0x111, "WM_COMMAND")

WM_COMMAND(wp, lp) {
   static ID_SUSPEND := 65305, timer := Func("WM_COMMAND").Bind("timer", "")
   if (wp = "timer")
      MsgBox, % "A_IsSuspended: " . A_IsSuspended ; send message here instead of MsgBox
   else if (lp = 0 && wp = ID_SUSPEND)
      SetTimer, % timer, -10
}

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Notify another script when I suspend a script using the tray icon

Post by AHKStudent » 27 Sep 2022, 21:53

teadrinker wrote:
27 Sep 2022, 18:40
Also you can intercept the command from the standard tray menu:

Code: Select all

OnMessage(0x111, "WM_COMMAND")

WM_COMMAND(wp, lp) {
   static ID_SUSPEND := 65305, timer := Func("WM_COMMAND").Bind("timer", "")
   if (wp = "timer")
      MsgBox, % "A_IsSuspended: " . A_IsSuspended ; send message here instead of MsgBox
   else if (lp = 0 && wp = ID_SUSPEND)
      SetTimer, % timer, -10
}
Great, thanks, this help me not having to modify the menu. Can you see if this is coded correctly? I am getting the messages correctly to my other script (22 and 23), however, is this the correct way to code this?

Thank you

Code: Select all

OnMessage(0x111, "WM_COMMAND")

WM_COMMAND(wp, lp) 
{
   static ID_SUSPEND := 65305, timer := Func("WM_COMMAND").Bind("timer", "")
   if (wp = "timer") {
      ;MsgBox, % "A_IsSuspended: " . A_IsSuspended ; send message here instead of MsgBox
	SetTitleMatchMode 2
	DetectHiddenWindows On
		if WinExist("scriptinventory.ahk ahk_class AutoHotkey") 
			if A_IsSuspended
				PostMessage, 0x5555, 11, 22  ; The message is sent  to the "last found window" due to WinExist() above.
			else
				PostMessage, 0x5555, 11, 23
		}
	   else if (lp = 0 && wp = ID_SUSPEND) {
		  SetTimer, % timer, -10
	  }
}
return 

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Notify another script when I suspend a script using the tray icon

Post by teadrinker » 27 Sep 2022, 23:30

AHKStudent wrote: is this the correct way to code this?
The code is correct. It can be simplified like this:

Code: Select all

OnMessage(0x111, "WM_COMMAND")

WM_COMMAND(wp, lp) 
{
   static ID_SUSPEND := 65305, timer := Func("WM_COMMAND").Bind("timer", "")
   if (lp = 0 && wp = ID_SUSPEND)
      SetTimer, % timer, -10
   else if (wp = "timer") {
      SetTitleMatchMode 2
      DetectHiddenWindows On
      if WinExist("scriptinventory.ahk ahk_class AutoHotkey")
         PostMessage, 0x5555, 11, A_IsSuspended ? 22 : 23
   }
}

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Notify another script when I suspend a script using the tray icon

Post by AHKStudent » 28 Sep 2022, 00:36

teadrinker wrote:
27 Sep 2022, 23:30
AHKStudent wrote: is this the correct way to code this?
The code is correct. It can be simplified like this:

Code: Select all

OnMessage(0x111, "WM_COMMAND")

WM_COMMAND(wp, lp) 
{
   static ID_SUSPEND := 65305, timer := Func("WM_COMMAND").Bind("timer", "")
   if (lp = 0 && wp = ID_SUSPEND)
      SetTimer, % timer, -10
   else if (wp = "timer") {
      SetTitleMatchMode 2
      DetectHiddenWindows On
      if WinExist("scriptinventory.ahk ahk_class AutoHotkey")
         PostMessage, 0x5555, 11, A_IsSuspended ? 22 : 23
   }
}
thank you

:thumbup: :thumbup: :thumbup: :thumbup:

Philister
Posts: 33
Joined: 01 Apr 2016, 07:31

Re: Notify another script when I suspend a script using the tray icon

Post by Philister » 12 Sep 2023, 13:26

In case anyone is looking for a way to do this that also works with suspend states changed via hotkeys, not just through the tray menu, I have set up a timer to give me notification:

Code: Select all

global SuspendState := 0
SetTimer, T_SuspendNotify, 250

T_SuspendNotify:
	if (A_IsSuspended and !SuspendState)
	{
		SuspendState := 1
		msgbox, Hotkeys suspended.
		return
	}
	if (!A_IsSuspended and SuspendState)
	{
		SuspendState := 0
		return
	}
return

Post Reply

Return to “Ask for Help (v1)”