Toggle that beeps when on/off

Post your working scripts, libraries and tools for AHK v1.1 and older
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Toggle that beeps when on/off

28 Jan 2018, 02:56

i noticed lot of people like to toggle things on and off, so i made this script today that toggles and beeps

probably been done a hundred times before if so just delete plz

Code: Select all

banana:=0

!y:: ;---------------------------------------alt + y
banana:=!banana
	if (banana=1)
	{
		SoundBeep, 1000, 200
		msgbox, its off
	}
	else if (banana=0)
	{
		SoundBeep, 2000, 500
		msgbox, its on again
	}
		return
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Toggle that beeps when on/off

28 Jan 2018, 07:49

If you want to make this script shorter, do this:

Code: Select all

Toggle := False

;====================================
; Alt + Y
;====================================
!y::
;====================================
	Toggle := !Toggle
	SoundBeep(Toggle ? 1000 : 2000, Toggle ? 200 : 500)
	MsgBox, % Toggle ? "its on again" : "its off"
	; MsgBox(Toggle := !Toggle ? "its on again" : "its off") ; V2
	Return

; Remove this function if in V2
SoundBeep(A, B) {
	SoundBeep, % A, % B
}
Short and sweet version. This allows for single line ifs, which work like this (In a nutshell):

Code: Select all

; Long ways.
If Var = Value
	A.Function()
Else
	B.Function()

; Single line.
Random_Unneeded_Function(Var = Value ? A.Function() : B.Function())
The question mark ? is the IF, and the colon : is the ELSE.
Short, easy, simple.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat


Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 87 guests