A toggle script with if statement.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
racer
Posts: 29
Joined: 07 May 2022, 15:02

A toggle script with if statement.

Post by racer » 23 May 2022, 11:46

Hi, it's me again :)

I was wondering if it is possible to make a toggle script with if statement. I press the Lbutton 2 times and it turns on/off the hotkeys. I already have another hotkey that also unsuspends hotkeys, which I press sometimes. So, Is it possible to check whether "suspend " is already on or off and make the toggle script act based on this statement?

I tried using the If (A_IsSuspended). Doesn't work or maybe I don't know how to use it. My code is below.

Code: Select all

~LButton::
Suspend, Permit
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
if (Toggle := !Toggle)
	 {
        SoundBeep, 1000
	Suspend, On
 }
else 
	{		
       Suspend, Off
       Sleep, 150
       SendInput {Esc} 
       SoundBeep, 2100
}
return

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

Re: A toggle script with if statement.

Post by mikeyww » 23 May 2022, 12:28

Code: Select all

~LButton::
Suspend, Permit
If (A_ThisHotkey != A_PriorHotkey || A_TimeSincePriorHotkey > 200)
 Return
Suspend
If !A_IsSuspended {
 SoundBeep, 1500
 Send {Esc}
} Else SoundBeep, 1000
Return

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A toggle script with if statement.

Post by Rohwedder » 23 May 2022, 12:38

Hallo,
try:

Code: Select all

~LButton::
Suspend, Permit
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
	if !A_IsSuspended
	{
		SoundBeep, 1000
		Suspend, On
	}
	else
	{
		Suspend, Off
		Sleep, 150
		SendInput {Esc}
		SoundBeep, 2100
	}
Return

racer
Posts: 29
Joined: 07 May 2022, 15:02

Re: A toggle script with if statement.

Post by racer » 23 May 2022, 14:50

Thanks a lot. They both work

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: A toggle script with if statement.

Post by arbibarbarona » 24 May 2022, 13:02

Code: Select all

!+p::
Suspend, Off
SoundBeep, 2000, 500
Tooltip, Ready to COLOR? Script ACTIVATED!
Sleep, 1500
Tooltip,
Return

!+o::
Suspend, On
SoundBeep, 500
ToolTip, Color Script SUSPENDED. Keyboard Restored.
Sleep, 1500
Tooltip,
return

!End:: ;????
I need help.
I wanted to use Alt+End to Suspend, off / Suspend, On, a script and still function as the two above hotkeys.

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

Re: A toggle script with if statement.

Post by mikeyww » 24 May 2022, 13:18

The answer is Suspend.

Post Reply

Return to “Ask for Help (v1)”