Why Isn't My Double-Press Being Detected Once A Loop Starts? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Why Isn't My Double-Press Being Detected Once A Loop Starts?

Post by Mulsiphix » 26 Jan 2022, 12:23

Once the loop has begun I am unable to double-press LShift to stop it. I do not understand why. If I bind a different hotkey to change the value of "Animation_Started", that hotkey triggers fine. But that isn't true for the LShift hotkey. Why is that?

Code: Select all

q::
Animation_Started := 1
Return


~LShift:: ; Enables a toggle for Push-To-Talk  in Mumble between On/Off
	if (A_PriorHotkey <> "~LShift" or A_TimeSincePriorHotkey > 350)
	{
		; Too much time between presses, so this isn't a double-press.
		Return
	}
; A double-press was detected, script executes the following If/Else code
If toggle := !toggle
   {
   Send, {Insert Down} ; Enable Push-To-Talk in Mumble
   Gosub, Start_Animation ; Begin animations
   }
Else
   {
   Animation_Started := 1 ; Change variable value to "1"
   MsgBox, A double-press was detected ; Confirm LShift double-press has triggered
   }
Return

Start_Animation:
Loop

{
MsgBox, Hello World

If (Animation_Started = 1) ; Check value of variable. If it is "1"
   Break ; End the loop immediately

Sleep, 500
MsgBox, Hello Again!

If (Animation_Started = 1) ; Check value of variable. If it is "1"
   Break ; End the loop immediately

Sleep, 500
}
Return

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Why Isn't My Double-Press Being Detected Once A Loop Starts?  Topic is solved

Post by amateur+ » 26 Jan 2022, 14:21

Code: Select all

toggle := 0
SetTimer, T, 100
T:
ToolTip, toggle= %toggle%
return

q::
toggle:= 0
Return

#MaxThreadsPerHotkey 2
~LShift:: ; Enables a toggle for Push-To-Talk  in Mumble between On/Off
	;~ MsgBox, % A_PriorHotkey
	if (A_PriorHotkey <> "~LShift" or A_TimeSincePriorHotkey > 350)
	{
		; Too much time between presses, so this isn't a double-press.
		Return
	}
; A double-press was detected, script executes the following If/Else code
If toggle := !toggle
   {
   Send, {Insert Down} ; Enable Push-To-Talk in Mumble
   SetTimer, Start_Animation, 500 ; Begin animations
   gosub, Start_Animation
   }
Else
   {
   MsgBox, A double-press was detected ; Confirm LShift double-press has triggered
   }
Return
#MaxThreadsPerHotkey 1

Start_Animation:
MsgBox, Hello World
If !toggle ; Check value of variable. If it is "1"
   SetTimer, Start_Animation, Off ; End the timer loop immediately
Return
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Why Isn't My Double-Press Being Detected Once A Loop Starts?

Post by Mulsiphix » 26 Jan 2022, 16:14

The ToolTip is really useful! Thank you. And #MaxThreadsPerHotkey is exactly what the doctor ordered. Thank you so much for taking the time to type this up for me. I found it very educational :dance:

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Why Isn't My Double-Press Being Detected Once A Loop Starts?

Post by amateur+ » 26 Jan 2022, 16:38

Was glad to help ;)
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Post Reply

Return to “Ask for Help (v1)”