a down getting stuck Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

a down getting stuck

Post by Cromax » 20 Mar 2023, 20:24

Code: Select all

#SingleInstance Force
#NoEnv
#Persistent
#InstallKeybdHook
#InstallMouseHook
#UseHook, On
#MaxThreadsperHotkey 2
#HotkeyModifierTimeout 200
#MaxHotkeysPerInterval 200
#Keyhistory 10
SetTitleMatchMode, 2
DetectHiddenWindows, On
SendMode, Input	
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
SetControlDelay 1
SetWinDelay, -1
SetKeyDelay, -1, 0
SetMouseDelay, -1
ListLines off
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
Thread, interrupt, 0 

$1::
SendEvent, {a down}
SetTimer, Rot, 40
return
	
$1 up::
SendEvent, {a up}
SetTimer, Rot, Off
return
have issue {a down} gets stuck for some reason tried multiple send modes and keywait inside 1 hotkey but for some reason it breaks settimer and it doesnt work even though settimer is above keywait.. tried if !getkeystate("1", "p") but its not working.. game is wow

[Mod edit: Moved topic to v1 help.]

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

Re: a down getting stuck

Post by mikeyww » 20 Mar 2023, 21:14

Hello,

I like how you've posted a script, but how about one that the reader can run to demonstrate the problem that you are having?

SetTimer is above KeyWait? Huh?

1. Post a real script.
2. Describe what the script does when you run it.
3. Describe what the script should do.

I think I would skip all the nonsense at the top unless you think it is actually essential for your script and you know what it does. At least it will help you debug and get your script working if it's not there and not important.

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 20 Mar 2023, 22:12

mikeyww wrote:
20 Mar 2023, 21:14
Hello,

I like how you've posted a script, but how about one that the reader can run to demonstrate the problem that you are having?

SetTimer is above KeyWait? Huh?

1. Post a real script.
2. Describe what the script does when you run it.
3. Describe what the script should do.

I think I would skip all the nonsense at the top unless you think it is actually essential for your script and you know what it does. At least it will help you debug and get your script working if it's not there and not important.
I said i tried keywait inside hotkey 1:: but it messes up settimer subroutine even though settimer was above it dunno why stops working.. otherwise everything works, only thing not working is Send, {a down} being stuck and Send, {a up} under $1 up:: doesnt register sometimes.. and script is 700 lines i dont want to post 700 lines.. in subroutine theres no a anywhere so shouldnt matter. subroutine is spells rotation based of pixels

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 20 Mar 2023, 22:18

issue is basically explained here https://www.reddit.com/r/AutoHotkey/comments/fd80vl/bug_sendmode_input_causes_inconsistent_and_stuck/ i have same problem.. and sendmode play doesnt work in wow

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 20 Mar 2023, 22:28

Code: Select all

#Include <TapHoldManager>
#Include <ShinsImageScanClass>
#SingleInstance Force
#NoEnv
#Persistent
#InstallKeybdHook
#InstallMouseHook
#UseHook, On
#MaxThreadsperHotkey 2
#HotkeyModifierTimeout 200
#MaxHotkeysPerInterval 200
#Keyhistory 10
SetTitleMatchMode, 2
DetectHiddenWindows, On
SendMode, Event	
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
SetControlDelay 1
SetWinDelay, -1
SetKeyDelay, -1, 0
SetMouseDelay, -1
ListLines off
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
Thread, interrupt, 0 


if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}



; TapandHold
;----------------------------

thm := new TapHoldManager(250,300,,,"ahk_exe Wow.exe")
thm.Add("+", Func("Move"))
thm.Add("0", Func("Defensive"))
thm.Add("F1", Func("Totem"))

Move(isHold, taps, state)
{

If(isHold == 0)
{
	if(state == -1)
		{
	
			if (taps == 1)
			{
				Send, {+}
			} 
			else if (taps == 2)
			{
				Send, +{0}
			}
		}
}
else if(isHold == 1)
{
	if (taps == 1)
		{
			Send, +{i}
		}
}

}

Defensive(isHold, taps, state)
{
If(isHold == 0)
{
	if(state == -1)
		{
	
			if (taps == 1)
			{
				Send, +{6}
			} 
			else if (taps == 2)
			{
				Send, +{4}
			}
		}
}
else if(isHold == 1)
{
	if (taps == 1)
		{
			Send, {e}
		}
}
}

Totem(isHold, taps, state)
{

If(isHold == 0)
{
	if(state == -1)
		{
	
			if (taps == 1)
			{
				Send, ^{2}
			} 
			else if (taps == 2)
			{
				Send, {'}
			}
		}
}
else if(isHold == 1)
{
	if (taps == 1)
		{
			Send, {f5}
		}
}

}
; TapandHold
;----------------------------




#If WinActive("ahk_exe Wow.exe")
scan := new ShinsImageScanClass()

	
	
$+1::
SetTimer, lashingflames, -50
return

lashingflames:

scan.autoUpdate := 0 ;when performaing many scans on 1 frame set this to 0
done := true
 
 
rx := 1010
ry := 220
rw := 517
rh := 494
   

  scan.update() ;only needed when setting the above to 0
    if (scan.ImageRegion("image.png",rx,ry,rw,rh,60,x,y,0,"LRBT")) {

	   
		rh := (y - ry) - 5
		x := x+60 ;scans to the left for flashing flames
		y := y+5
		w := 40 
		h := 40
		mousemove,x,y
		sleep 20
		send +{1}
		done := false
		
	   
	  
	   
	   
	   
	if (rh <= 0)
		SetTimer,lashingflames, Off
    } else 
    {
	    
	Send, 6
		
    }


scan.autoUpdate := 1
return

	
	$f4::
	SendEvent, {s down}
	SetTimer, Rotation, -40
	return
	
	
	$f4 up::
	SendEvent, {s up}
	SetTimer, Rotation, Off
	return
	
	$4::
	SetTimer, wft, -40
	return
	
	
	wft:
	
	PixelSearch, FoundX, FoundY, 1144, 458, 1179, 489, 0xE5D5F2, 10, Fast RGB 
	If (ErrorLevel = 0)
	{	
		
		Send, +{r}
		
	}
	else
	{	
		PixelSearch, FoundX, FoundY, 1096, 458, 1132, 487, 0x5F7661, 10, Fast RGB  
		If (ErrorLevel = 0)
		{	
			
			Send, +{g}
			
			
		}
		else
		{	
			
			PixelSearch, FoundX, FoundY, 1466, 1130, 1530, 1164, 0xF3EEC8, 10, Fast RGB 
			If (ErrorLevel = 1)
			{
				Send, {4}
				
			}
		}
	}			
	Return
	
	
	
	$4 up::
	SetTimer, wft, Off
	Return
	
	
	
	$5::
	SetTimer, Primordial, -40
	return
	
	
	Primordial:
		PixelSearch, FoundX, FoundY, 1092, 1052, 1112, 1069, 0x09E1B5, 10, Fast RGB 
		If (ErrorLevel = 0)
		{	
			Send, {7}
			Send, {f8}
			
		}
		else
		{
			
			PixelSearch, FoundX, FoundY, 1113, 1234, 1124, 1248, 0xF7DF10, 10, Fast RGB 
			If (ErrorLevel = 0)
			{	
				
				Send, {7}
				Send +{6}
				
			}
			else
			{
				
				PixelSearch, FoundX, FoundY, 1372, 1145, 1403, 1192, 0x9A1011, 10, Fast RGB 
				If (ErrorLevel = 0)
				{	
					Send, {7}
					Send, {2}
					
				}
				else
				{
					
					PixelSearch, FoundX, FoundY, 1273, 1057, 1285, 1064, 0xB54402, 10, Fast RGB
					If(ErrorLevel = 0)
					{
						
						Send {5}
						
					}
				}
			}
		}
	Return
	
	$5 up::
	SetTimer, Primordial, Off
	return
	
	$8::
		if(scan.imageregion("fr1.png",321,20,1766,712,80,x,y,0,"BTLR"))
		{	
			MouseMove, x+85,y+10
			Send, 8
		}else
		{
			
		
		if(scan.imageregion("image.png",321,20,1766,712,80,x,y,0,"BTLR"))
		{	
			MouseMove, x+85,y+10
			Send, 8
		}
		else {
			Send, 8
		}
		}
	Return
	
	$1::
	Send, {a down}
	SetTimer, Rotation, -30
	return
	
	$1 up::
	Send, {a up}
	SetTimer, Rotation, Off
	return
	
	
	$2::
	Settimer, Rotation, -30
	Send, {d down}
	return
	
	
	$2 up::
	Send, {d up}
	SetTimer, Rotation, Off
	return
	
	
	
	
	$3::	
	SetTimer, Rotation, -30
	return
	
	Rotation:
	
	PixelSearch, FoundX, FoundY, 1196, 1080, 1205, 1087, 0x1A6702, 10, Fast RGB 
	If (ErrorLevel = 0)
	{
		
		SendInput, {3}
		
	}
	
	
	scan.AutoUpdate := 0 ;class will not update buffer on calls, must update once manually
	scan.Update()
	
	if(scan.imageregion("1.png",1211,986,34,38,70,"BTLR"))
	{
		SendInput, {q}
	}
	
	if(scan.imageregion("2.png",1211,986,34,38,70,"BTLR"))
	{
		SendInput, {q}
	}

	if(scan.imageregion("3.png",1211,986,34,38,70,"BTLR"))
	{
		SendInput, {2}
	}

	if(scan.imageregion("4.png",1211,986,34,38,70,"BTLR"))
	{
		SetTimer, lashingflames, -30
	}
	
	if(scan.imageregion("5.png",1211,986,34,38,70,"BTLR"))
	{
		SendInput, {0}
	}

	if(scan.imageregion("6.png",1211,986,34,38,80,"BTLR"))
	{
		SendInput, {F3}
	}


	if(scan.imageregion("7.png",1211,986,34,38,70,"BTLR"))
	{
		SendInput, {'}

	}

	if(scan.imageregion("8.png",1211,986,34,38,60,"BTLR"))
	{
		SendInput, {1}

	}

	if(scan.imageregion("9.png",1211,986,34,38,60,"BTLR"))
	{
		SendInput, {t}

	}

	if(scan.imageregion("10.png",1211,986,34,38,60,"BTLR"))
	{
		SendInput, {3}

	}
	
	scan.AutoUpdate := 1	
	return

	
	
	
	$3 up::
	SetTimer, Rotation, Off
	return
	
	
	
	
	$6::
	SetTimer, ss, -40
	return
	
	
	ss:
		
		PixelSearch, FoundX, FoundY, 1116, 1070, 1136, 1091, 0x747474, 10, Fast RGB ; ST
		If (ErrorLevel = 0)
		{	
			
			PixelSearch, FoundX, FoundY, 1175, 1143, 1184, 1152, 0x1B9202, 10, Fast RGB 
			{
				
				Send, {6}
				
			}
			else
			{	
				PixelSearch, FoundX, FoundY, 1112, 1143, 1119, 1150, 0x881112, 10, Fast RGB 
				If (ErrorLevel = 0)
				{	
					Send {0}
					
				}
				else
				{
					PixelSearch, FoundX, FoundY, 1156, 1150, 1176, 1165, 0xFD9600, 10, Fast RGB 
					If (ErrorLevel = 0)
					{	
						
						Send {6}
						
					}
					else
					{	
						PixelSearch, FoundX, FoundY, 1104, 1142, 1125, 1172, 0xD6E5ED, 10, Fast RGB 
						If (ErrorLevel = 0)
						{	
							
							Send, {0}
							
						}
					
						
					}
				}	
			}	
			
		}
		else
		{	
			
			PixelSearch, FoundX, FoundY, 1175, 1143, 1184, 1152, 0x1B9202, 10, Fast RGB 
			If (ErrorLevel = 0)
			{
				
				Send, {6}
				
			}
			else
			{	
				PixelSearch, FoundX, FoundY, 1112, 1143, 1119, 1150, 0x881112, 10, Fast RGB 
				If (ErrorLevel = 0)
				{	
					Send {0}
					
				}
				else
				{
					
					PixelSearch, FoundX, FoundY, 1156, 1150, 1176, 1165, 0xFD9600, 10, Fast RGB 
					If (ErrorLevel = 0)
					{	
						
						Send {6}
						
					}
					else
					{
						
						
						PixelSearch, FoundX, FoundY, 1104, 1142, 1125, 1172, 0xD6E5ED, 10, Fast RGB 
						If (ErrorLevel = 0)
						{	
							
							Send, {0}
							
							
						}
					}
				}	
			}	
			
			
			
		}
	Return
	

	
	
	$6 up::
	SetTimer, ss, Off
	return
	
	
	
	$7::
	SetTimer, cd, -40
	Return
	
	
	cd:
	Send, {7}
	Send, {r}
	Send, {f7}
	return
	
	
	
	
	$7 up::
	SetTimer, cd, Off
	return
	
	MButton::
	Send, {e}
	Send, {f}
	Send, +{3}
	Send, {0}
	return
	
	$9::
	SetTimer, Defensives, -40
	return
	
	Defensives: 
	
	
	
	PixelSearch, FoundX, FoundY, 1245, 1197, 1271, 1224, 0x730712, 10, Fast RGB
	If (ErrorLevel = 0) 
	{	
		Send, {e}
		Send, {f}
		PixelSearch, FoundX, FoundY, 1195, 1269, 1206, 1280, 0xFCFABD, 10, Fast RGB 
		If (ErrorLevel = 0)
		{
			Send, +{3}
			Send, {9}
			
		}
		else
		{	
			Send, +{e}
			Sleep, 30
			Send, +{4}
			Sleep, 30
			
			
		}	
	}
	else        	
	{	
		;PixelSearch, FoundX, FoundY, 1147, 1060, 1164, 1080, 0xB9A247, 10, Fast RGB 
		;If (ErrorLevel = 0)
		;{	
			
			PixelSearch, FoundX, FoundY, 1235, 1191, 1267, 1207, 0xDEBB11, 10, Fast RGB 
			If (ErrorLevel = 0)
			{	
				Send, {e}
				Send, {f}
				PixelSearch, FoundX, FoundY, 1195, 1269, 1206, 1280, 0xFCFABD, 10, Fast RGB 
				If (ErrorLevel = 0)
				{
					Send, +{3}
					Send, {9}
					
				}
			}
			else
			{
				Send, {e}
				Send, {f}
				PixelSearch, FoundX, FoundY, 1189, 1271, 1196, 1278, 0xFDF4A4, 10, Fast RGB 
				If (ErrorLevel = 0)
				{	
					Send, +{3}
					Send, {9}
					
				}
				else
				{
					Send, {9}
				}
				
			}
			
		;}
		;else
		;{
			;Send, ^{f}
			
			
		;}
		
		
	}
	Return
	
	$9 up::
	SetTimer, Defensives, Off
	return

#If
+!s::Suspend, Toggle
+!a::Reload
there you go whole script

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

Re: a down getting stuck

Post by mikeyww » 20 Mar 2023, 23:09

I can offer some tips to help you debug:

1. Simplify and shorten your script for the purpose of testing.
2. Test in some program other than your game, to start.
3. You mentioned that "Send, {a up} under $1 up:: doesnt register". Add some logging, a sound, or visual confirmation, and check the KeyHistory to see what is really happening with the keys, especially since it appears that you are trying to send multiple keys at the same time.

If you press 1, it will repeatedly trigger the hotkey. This may not be doing what you want. In particular, a timer is reset every time the command is executed. To prevent the repeating, you can add KeyWait. An example is below. If you are pressing multiple keys at the same time, you can use your original key-up approach but also add a KeyWait to the key-down subroutine.

Code: Select all

#Requires AutoHotkey v1.1.33

1::
Send {a down}
SetTimer Rot, 400
SoundBeep 1500
KeyWait 1
Send {a up}
SetTimer Rot, Off
SoundBeep 1000
Return

Rot:
ToolTip % tip .= "x"
Return
I suggest working with the code here, and modifying it, until you get what you want with the key and the timed subroutine. If you cannot get this short script to work, then expanding the script with 600 more lines is unlikely to help.

Timed subroutines are generally short in duration. If your timed subroutine requires more time than the timer frequency itself, you might get unexpected results. At the least, you would have a possible timing error, because the next iteration cannot start until the current iteration finishes. For most situations where you are searching for pixels or images, a timer with a fast cycle may not be the best choice for a loop, as compared to a Loop or While command, for example.

Best of luck!

Code: Select all

#Requires AutoHotkey v1.1.33

1::
Send {a down}
SoundBeep 1500
While GetKeyState(1, "P") {
 Sleep 300
 If GetKeyState(1, "P")
  ToolTip % tip .= "x"
}
Send {a up}
SoundBeep 1000
Return
Once a loop's iteration starts, it continues to completion unless interrupted by a hotkey, Break, Continue, etc.

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 20 Mar 2023, 23:41

i dont understand why but first what you posted as alone script it works perfectly but when i put in my own script it beeps 2 times for key pressed and key up.. as for loops i have issue with it, when i want break out with condition if key not pressed it gets stuck and its inconsistent

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

Re: a down getting stuck

Post by mikeyww » 21 Mar 2023, 06:05

In that case, I would start with step #1 of my recommendations!

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 21 Mar 2023, 06:32

it was #maxthreadsperhotkey 2

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

Re: a down getting stuck

Post by mikeyww » 21 Mar 2023, 07:43

Thank you. I see no need for that in the initial script as shown, but if a hotkey subroutine has not completed when you are trying to trigger it again, it would be ignored by default (without the increase in max threads).

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 28 Mar 2023, 20:20

still getting stuck and i dunno anymore

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: a down getting stuck

Post by swagfag » 28 Mar 2023, 22:04

id add wildstar * to these ...Up:: hotkeys

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 28 Mar 2023, 22:46

yeah will try that also.. ty for suggestion

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 30 Mar 2023, 20:54

i found whats wrong.. it happens when mouse keys are pressed together with other hotkeys and Sendmode input is used.. i guess i am stuck in send mode event

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck

Post by Cromax » 31 Mar 2023, 20:22

nope still gets stuck

Cromax
Posts: 22
Joined: 26 Jan 2021, 15:27

Re: a down getting stuck  Topic is solved

Post by Cromax » 11 Apr 2023, 21:27

if anyone still has issues for me solution was #MenuMaskKey vkFF bc windows has shortcuts ctrl+something and if you use it in script it gets stuck and breaks the script..

Post Reply

Return to “Gaming Help (v1)”