SoundBeep after Loop, break

Get help with using AutoHotkey and its commands and hotkeys
User avatar
moonmanmacros
Posts: 3
Joined: 05 Apr 2020, 15:53

SoundBeep after Loop, break

05 Apr 2020, 16:12

Here is the code for one of my most used scripts which turns double taps of the Alt keys into Copy paste functions. I want to add a sound beep at the end of the copy loop to confirm that the script is running and working whenever I double tap LAlt, but SoundBeep will trigger every time I release the alt key even if doing so does not triggert hot key. It seems to happen regardless of where I put SoundBeep. Is there another way to verify that my double tap has sucessfully copied to the clipboard? The only other way I have pulled it off is a total pain.

~LAlt::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
Run, %A_ScriptDir%\copysoundbeep.exe
return

Code: Select all

~LAlt up::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
	clipboard := ""  ; empty clipboard
Loop
{
	Send, ^c
	ClipWait, 1		; wait for the clipboard to contain data
	if (!ErrorLevel)    ; If NOT ErrorLevel clipwait found data on the clipboard
    break
    ;SoundBeep, 750, 500
}
Return

~RAlt::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
	Send, ^v
Return
User avatar
boiler
Posts: 5223
Joined: 21 Dec 2014, 02:44

Re: SoundBeep after Loop, break

05 Apr 2020, 16:59

The only command you have executing on the condition that it was double-clicked is the clipboard := "" line. So your script is executing everything below it (the loop) every time you release LAlt whether it was double tapped or not. You need to use { } to designate a code block after the If statement so that all of it gets executed only when the condition is true:

Code: Select all

~LAlt up::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
{
	clipboard := ""  ; empty clipboard
	Loop
	{
		Send, ^c
		ClipWait, 1		; wait for the clipboard to contain data
		if (!ErrorLevel)    ; If NOT ErrorLevel clipwait found data on the clipboard
		break
		SoundBeep, 750, 500
	}
}
Return

~RAlt::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
	Send, ^v
Return
User avatar
moonmanmacros
Posts: 3
Joined: 05 Apr 2020, 15:53

Re: SoundBeep after Loop, break

05 Apr 2020, 23:11

I did not realize it would be that easy to just place one set of brackets inside another. It now works great! Guess im still to used to the double and triple quotes that you would normal use in Excel for something like this.

Code: Select all

~LAlt up::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 250)
{
	clipboard := ""  ; empty clipboard
Loop
{
	Send, ^c
	ClipWait, 1		; wait for the clipboard to contain data
	if (!ErrorLevel)    ; If NOT ErrorLevel clipwait found data on the clipboard
   break
}
SoundBeep, 750, 500
}
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Baby Flurry Heart, Bruce27, Clemens375, himanshu, Rohwedder, songdg and 148 guests