Just a quick fix needed for a pause and unpausing script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
[m]
Posts: 21
Joined: 05 May 2020, 14:12

Just a quick fix needed for a pause and unpausing script

14 Apr 2021, 19:04

The below script is just a small part but at the moment it goes from a 'script is running' (green icon in the taskbar) state to Pause state when i get discord on top.

Code: Select all

SetTimer tTimer,500
tTimer:
  If (WinActive("ahk_exe Discord.exe") && !fD){
       Pause, On
  If !WinActive("ahk_exe Discord.exe")
       Pause, Off
Just want this to have the script unpaused when discord is on top and when clicked outside of discord or any other window the script pauses.
Will appreciate any help.
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Just a quick fix needed for a pause and unpausing script  Topic is solved

14 Apr 2021, 19:27

Remarks section of Pause documentation wrote:Whenever any thread is paused, timers will not run.

What you can do is have another script running that will monitor whether the Discord window is active and pause your other script accordingly. Example #2 in the Pause documentation shows how to pause another script:

Code: Select all

DetectHiddenWindows, On
WM_COMMAND := 0x0111
ID_FILE_PAUSE := 65403
PostMessage, WM_COMMAND, ID_FILE_PAUSE,,, C:\YourScript.ahk ahk_class AutoHotkey
Last edited by boiler on 14 Apr 2021, 19:37, edited 2 times in total.
User avatar
[m]
Posts: 21
Joined: 05 May 2020, 14:12

Re: Just a quick fix needed for a pause and unpausing script

14 Apr 2021, 19:33

Oh...so it doesn't work in the first place then. Are there workarounds or should i just use this with a hotkey as i did before?
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Just a quick fix needed for a pause and unpausing script

14 Apr 2021, 19:35

Yeah, just edited my post above to show one approach.
User avatar
[m]
Posts: 21
Joined: 05 May 2020, 14:12

Re: Just a quick fix needed for a pause and unpausing script

15 Apr 2021, 13:13

Any way to get this working? Or like how do I make it send a pause to the other script when discord isn't active? Or is ifWinActive even the right thing to use?
https://www.autohotkey.com/boards/viewtopic.php?t=47700

Because I couldn't. (I discovered that piece of code that sends a pause to another script for the first time so i'm unexperienced in this territory.)

Code: Select all

If WinActive("ahk_exe Discord.exe") && (!A_IsPaused)
Pause, On
If !WinActive("ahk_exe Discord.exe") && (A_IsPaused)
Pause, Off
DetectHiddenWindows, On
WM_COMMAND := 0x0111
ID_FILE_PAUSE := 65403
PostMessage, WM_COMMAND, ID_FILE_PAUSE,,, C:\[path to my script] ahk_class AutoHotkey
Above code is just giving you the rough idea, it's probably wrong.
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Just a quick fix needed for a pause and unpausing script

15 Apr 2021, 13:34

You can't use A_IsPaused because that only tells you about this script, not another script. You don't even need it since you're going to send a message to toggle it from whatever state it's in. And you don't use the Pause command to pause. That would pause this script. You pause the other script with the PostMessage. And then you need to loop. It's like this:

Code: Select all

DetectHiddenWindows, On
WM_COMMAND := 0x0111
ID_FILE_PAUSE := 65403

loop {
	WinWaitActive, ahk_exe Discord.exe
	PostMessage, WM_COMMAND, ID_FILE_PAUSE,,, C:\[path to my script] ahk_class AutoHotkey
	WinWaitNotActive, ahk_exe Discord.exe
	PostMessage, WM_COMMAND, ID_FILE_PAUSE,,, C:\[path to my script] ahk_class AutoHotkey
}
return

Esc::ExitApp
User avatar
[m]
Posts: 21
Joined: 05 May 2020, 14:12

Re: Just a quick fix needed for a pause and unpausing script

15 Apr 2021, 14:04

Yeah I thought of mixing it like this and I figured it had to be looped too. I just was unsure how. Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998 and 243 guests