Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Toggling Suspend Hotkeys On/Off & Sounds for Each


  • Please log in to reply
5 replies to this topic
Wranger
  • Members
  • 3 posts
  • Last active: Aug 03 2012 12:16 PM
  • Joined: 03 Aug 2012
What I have is Ctrl+Alt+F12 to Toggle the Suspension of Hotkeys on and off.

That's achievable with:

^!F12::Suspend, Toggle


What I would also like is to have two different sounds play when it's toggled on and off. Let's say for example; a high pitch for on, and a low pitch for off.

The closest thing I have so far is just a single beep that plays with the toggle:

^!F12::
Suspend, Permit
soundbeep
Suspend
return


Is there some way I can incorporate a 'toggle=if true' or something like that? Thanks in advance!

G. Sperotto
  • Members
  • 539 posts
  • Last active: Jun 20 2015 04:54 PM
  • Joined: 12 Dec 2011
Hi Wranger.

Welcome to the AutoHotkey community forums.

You can set a variable that will turn false if true and true if false to rule toggle states.

F12::
Suspend, permit
if (State = 0) [color=#008000]; Checks the current state of variable "State". And if it is False (zero)...[/color]
{
	SoundBeep 6000, 200 
	Sleep 100
	SoundBeep 6000, 200 [color=#008000]; Plays two beeps.[/color]
	State++ [color=#008000]; And changes the value of variable "State" to True (one).[/color]
}
Else [color=#008000]; Otherwise...[/color]
{
   State := 0 [color=#008000]; Sets the value of State variable to False (zero)[/color]
   Soundbeep 8000, 500 [color=#008000]; And plays a single beep.[/color]
}
Suspend, Toggle [color=#008000]; In both cases suspend is toggled, but due to the overall logic of the routine, it is toggled to On whenever State was zero and off whenever it was one.[/color]
Return

Best wishes :wink:

"What is a suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!


Wranger
  • Members
  • 3 posts
  • Last active: Aug 03 2012 12:16 PM
  • Joined: 03 Aug 2012
Works wonderfully, thanks!

I only wonder out of curiosity how I can play a sound that isn't a beep, I tried to substitute with something SoundPlay, à la http://www.autohotke...s/SoundPlay.htm, but it didn't work?

G. Sperotto
  • Members
  • 539 posts
  • Last active: Jun 20 2015 04:54 PM
  • Joined: 12 Dec 2011
SoundPlay is indeed the command you are looking for.

The script bellow uses two different system sounds.

F12::
Suspend, permit
if (State = 0) [color=#008000]; Checks the current state of variable "State". And if it is False (zero)...[/color]
{
   SoundPlay *48 [color=#008000]; Plays a system sound...[/color]
   State++ [color=#008000]; And changes the value of variable "State" to True (one).[/color]
}
Else [color=#008000]; Otherwise...[/color]
{
   State := 0 [color=#008000]; Sets the value of State variable to False (zero)...[/color]
   SoundPlay *16 [color=#008000]; And plays another system sound.[/color]
}
Suspend, Toggle [color=#008000]; In both cases suspend is toggled, but due to the overall logic of the routine, it is toggled to On whenever State was zero and off whenever it was one.[/color]
Return

But SoundPlay can also play other Audio Files. To do that, provide an absolute path (such as c:\ExampleFolder\ExampleSound.wav) as the first parameter of the command.

SoundPlay C:\ExampleFolder\ExampleSound.wav

Also, Keep this in mind:

All Windows OSes should be able to play .wav files. However, other files (.mp3, .avi, etc.) might not be playable if the right codecs or features aren't installed on the OS.


"What is a suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!


Wranger
  • Members
  • 3 posts
  • Last active: Aug 03 2012 12:16 PM
  • Joined: 03 Aug 2012
Exactly what I was looking for, thanks again!

Rufus Shinra
  • Members
  • 1 posts
  • Last active: Nov 04 2015 05:52 AM
  • Joined: 04 Nov 2015

here is a suspend toggle in the F12 key, just need to add the soundplay to it.

 

F12::
Suspend, permit
if (A_IsSuspended = "0")
{
     TrayTip, Suspended, %A_ScriptName%, , 1
}
Else
{
     TrayTip, UnSuspended, %A_ScriptName%, , 1
}
Suspend, Toggle
Return