OnSuspend?
-
- Posts: 18
- Joined: 11 Oct 2017, 09:04
OnSuspend?
In v2 is there a onSuspend function similar to onExit? It seems this would be pretty useful generally, as well as to me for a script I'm working on, but I can't seem to find any official way of detecting when a script is suspended, or unsuspended.
-
- Posts: 18
- Joined: 11 Oct 2017, 09:04
Re: OnSuspend?
Oh yes, I know about that variable, sorry if I wasn't clear. I'm looking for something that will trigger when the script is suspended or unsuspended; while the variable lets you check you'd have to have something like a constant while loop running in the script monitoring when the variable changes, which I don't want to do.
onExit is nice because it calls its given function automatically when the script exits.
onExit is nice because it calls its given function automatically when the script exits.
Re: OnSuspend?
I'm not aware of any callback for the Suspend command, and the docs don't mention any such callback.
You could make your own wrapper function to do this, though that might be more trouble than it is worth.
You could make your own wrapper function to do this, though that might be more trouble than it is worth.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: OnSuspend?
Code: Select all
SuspendC := Suspend.GetMethod("Call")
Suspend.DefineProp("Call", {
Call:(this, mode:=-1) => (SuspendC(this, mode), OnSuspend(A_IsSuspended ? 1 : 0))
})
OnSuspend(mode) {
if mode = 1
{
MsgBox "Suspend is on"
}
else if mode = 0
{
MsgBox "Suspend is off"
}
}
#SuspendExempt true
1::Suspend 0
2::Suspend 1
3::Suspend -1
#SuspendExempt false
Re: OnSuspend?
@ntepa
I was trying to figure out how to do that. Thanks for posting.
I was trying to figure out how to do that. Thanks for posting.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
-
- Posts: 18
- Joined: 11 Oct 2017, 09:04
Re: OnSuspend?
Thanks for the help! That wrapper generally works, though it misses suspensions done from the tray icon and main window unfortunately. Probably the best solution for now though.
Re: OnSuspend?
Now it detects if you suspended from the tray, or main window.
I got the numbers 65305 and 65404 using:
Code: Select all
SuspendC := Suspend.GetMethod("Call")
Suspend.DefineProp("Call", {
Call:(this, mode:=-1) => (SuspendC(this, mode), OnSuspend(A_IsSuspended))
})
OnMessage(0x111, OnSuspendMsg)
OnSuspendMsg(wp, *) {
if (wp = 65305) || (wp = 65404)
OnSuspend(!A_IsSuspended)
}
OnSuspend(mode) {
if mode = 1
{
MsgBox "Suspend is on"
}
else if mode = 0
{
MsgBox "Suspend is off"
}
}
#SuspendExempt true
1::Suspend 0
2::Suspend 1
3::Suspend -1
#SuspendExempt false
Code: Select all
OnMessage(0x111, WM_COMMAND)
WM_COMMAND(wparam, lparam, msg, hwnd) {
OutputDebug "wp: " wparam " | lp: " lparam "`n"
}
Last edited by ntepa on 19 Dec 2022, 21:59, edited 2 times in total.
-
- Posts: 18
- Joined: 11 Oct 2017, 09:04
Re: OnSuspend?
That's crazy! And works perfectly! Thanks for this.
Re: OnSuspend?
I made some edits. The suspend state was switched.
Re: OnSuspend?
Suspend.GetMethod("Call") == Func.Prototype.Call
so you can use (Func.Prototype.Call)(this, ...).
so you can use (Func.Prototype.Call)(this, ...).
Re: OnSuspend?
like this? @thqby
Code: Select all
Suspend.DefineProp("Call", {
Call:(this, mode:=-1) => ((Func.Prototype.Call)(this, mode), OnSuspend(A_IsSuspended))
})
Re: OnSuspend?
Very cool @thqby.
Thanks.
Thanks.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »