Need to show tooltip when toggling Suspend Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Need to show tooltip when toggling Suspend

Post by ry3ks3u_m4dd0ns » 29 Mar 2017, 09:33

I'm working on a script that temporarily disables the number keys on top of the QWERTYUIOP, and it sort of works, just not the way I expected it to. Yes, the script gives me a tooltip and then suspends, but then it also closes itself.

Here's what I have so far.

Code: Select all

ScriptStat := false
Numpad0::
	If ScriptStat
	{
		ScriptStat := false
		Tooltip, Script reenabled.
		Suspend
		return
	}
	ScriptStat := true
	Tooltip, Script suspended.
	Suspend
Any help would be appreciated, and also all roasts on how I'm a scrub at this is also welcome.

User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Need to show tooltip when toggling Suspend

Post by evilC » 29 Mar 2017, 09:44

Code: Select all

ScriptStat := false
Numpad0::
	Suspend	; Make this hotkey immune to suspend, so it can Un-Suspend
	If ScriptStat
	{
		ScriptStat := false
		Tooltip, Script reenabled
		Suspend, Off
	} else {
		ScriptStat := true
		Tooltip, Script suspended.
		Suspend, On
	}
	return

ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Need to show tooltip when toggling Suspend

Post by ry3ks3u_m4dd0ns » 29 Mar 2017, 09:51

evilC wrote:

Code: Select all

ScriptStat := false
Numpad0::
	Suspend	; Make this hotkey immune to suspend, so it can Un-Suspend
	If ScriptStat
	{
		ScriptStat := false
		Tooltip, Script reenabled
		Suspend, Off
	} else {
		ScriptStat := true
		Tooltip, Script suspended.
		Suspend, On
	}
	return
Thank you, evilC!
This helped a lot.

User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Need to show tooltip when toggling Suspend  Topic is solved

Post by Nextron » 29 Mar 2017, 10:20

Although the above fixes your code, there are some remarks:
• Suspend is equivalent to Suspend, Toggle, so you're already changing the suspend state and possible doing it again later in the code.
• There can be valid reasons to keep you own suspend state variable, but there is already a more reliable one built in: A_IsSuspended.
So you can reduce and improve it to:

Code: Select all

Numpad0::
	Suspend
	ToolTip % A_IsSuspended ? "Script suspended" : "Script reenabled"
Return

AlFlo
Posts: 345
Joined: 29 Nov 2021, 21:46

Re: Need to show tooltip when toggling Suspend

Post by AlFlo » 30 Sep 2022, 12:35

I tried using Nextron's script in my AHK autocorrect script. It works to toggle suspend on/off, but doesn't create a tooltip. I also changed tooltip to msgbox, but it doesn't create a message box, either.

What am I doing wrong?

AlFlo
Posts: 345
Joined: 29 Nov 2021, 21:46

Re: Need to show tooltip when toggling Suspend

Post by AlFlo » 01 Oct 2022, 13:39

Never mind ... I figured it out:

Code: Select all

^y::
Suspend

ToolTip,% a_isSuspended?"Regular":"Autocorrect", 1400, 2800
SetTimer, RemoveToolTip, -2000
return

RemoveToolTip:
ToolTip
return

Post Reply

Return to “Ask for Help (v1)”