My scripts stop working randomly

Ask gaming related questions (AHK v1.1 and older)
lone_lynx
Posts: 2
Joined: 01 May 2024, 14:57

My scripts stop working randomly

01 May 2024, 15:10

I have autofire scripts (for J, K, L keys) and 2 other scripts which just tap on 2 other buttons instantly. I use the scripts while I am playing games, but after some time (generally 30 mins to an hour) they just randomly stop working. Also, my keyboard and mouse controls get very weird, for example, when I try to click on an icon on the desktop, it just selects multiple icons and try to start them. My keys (including the ones that I don't have a macro for) also get very weird and do not do what they are supposed to do. I disabled sticky keys on my computer, so when I repeatedly tap on shift, I doesn't open the sticky keys. Also, the macros don't stop after a specific macro is activated, it just stops randomly (I already don't repeatedly tap on LShift for the macro, there are at least 10 seconds between consecutive taps). I am open to any solution which does not get stuck and allows me to press up to 3 macros simultaneously (including possible v2 solutions). How can I solve this issue?

Note 1: I generally hold autofire keys (at most 2) and tap other 2 macros once (maybe while holding 2 autofire macros)
Note 2: I am using Windows 10.
Note 3: Although there are better ways to write these codes, I tried a few and all of them got stuck (continued autofiring after I release the key) and did not work simultaneously (I generally press J&L or K&L together continuously, so if one does not work when I try to press while pressing the other, it is a big problem for me).

Autofire script (same for K and L):

Code: Select all

#NoEnv 
SendMode Input 
SetWorkingDir %A_ScriptDir%  
#Persistent
#IfWinActive, ahk_exe HD-Player.exe
$j::
	GoSub, AutoFireJ
return

AutoFireJ:
	Send, j
	if GetKeyState("j", "P")
		SetTimer, AutoFireJ, -16
return
The other scripts: (I did not use the same script in the pinned post since it does not work in the game, there has to be some delay.)

1 - Send A and T after LShift is tapped

Code: Select all

#NoEnv
SendMode Input 
SetWorkingDir %A_ScriptDir% 
#Persistent
#IfWinActive, ahk_exe HD-Player.exe
$SC02A::-
	While GetKeyState("SC02A", "P") {-
		SendInput, a
		Sleep, 20
		SendInput, t
		Sleep, 20
	}
Return
2 - Send Space and T when SC027 (İ on my keyboard) is tapped:

Code: Select all

#NoEnv
SendMode Input 
SetWorkingDir %A_ScriptDir% 
#Persistent
#IfWinActive, ahk_exe HD-Player.exe
$SC027::
	While GetKeyState("SC027", "P") {
		SendInput, {Space}
		Sleep, 20
		SendInput, t
		Sleep, 20
	}
Return
User avatar
mikeyww
Posts: 27146
Joined: 09 Sep 2014, 18:38

Re: My scripts stop working randomly

04 May 2024, 07:32

Welcome to this AutoHotkey forum!

My approach would be to start with one simple hotkey in a simplified script, and get it working first. An example is below. After it works, add one more small part, and re-test.

Send always sends to the active window. When a different window becomes active, you may get unexpected results.

Code: Select all

j::
SetTimer Fire, 16
Gosub Fire
SoundBeep 1500
KeyWait j
Return

j Up::
SetTimer Fire, Off
SoundBeep 1000
Return

Fire:
SetKeyDelay 25, 25
SendEvent j
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
lone_lynx
Posts: 2
Joined: 01 May 2024, 14:57

Re: My scripts stop working randomly

05 May 2024, 15:41

mikeyww wrote:
04 May 2024, 07:32
Welcome to this AutoHotkey forum!

My approach would be to start with one simple hotkey in a simplified script, and get it working first. An example is below. After it works, add one more small part, and re-test.

Send always sends to the active window. When a different window becomes active, you may get unexpected results.

Code: Select all

j::
SetTimer Fire, 16
Gosub Fire
SoundBeep 1500
KeyWait j
Return

j Up::
SetTimer Fire, Off
SoundBeep 1000
Return

Fire:
SetKeyDelay 25, 25
SendEvent j
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
Thank you for your help! I tried your script and it still has the same issue of randomly stopping. Though, it doesn't get stuck. I modified the code you posted a bit. I want the macro to autofire about 60 times per second, so I removed SendKeyDelay. Was it important for the macro to not stop randomly or misbehave? Should I have done it differently by setting timer to 10, and key delay to 6? Also, are the keywords like #Persistent, #NoEnv, SendMode Input, SetWorkingDir %A_ScriptDir% important for my case? Should I use them? I have searched on internet but there are general explanations. I am wondering if they are applicable or relevant to my case.

Also, yes, I am new to AHK. I only use it for the game for now. A lot of people who are really good at the game also use these macros, but noone shares their scripts. I could also work with v2 macros but I started with the code that I posted which works on v1 without getting stuck. If there are better ways to handle these, I would love to use them. I got help from someone on reddit (for v2 script) and his/her script was having the issue of getting stuck: https://www.reddit.com/r/AutoHotkey/s/WFniZh5G4g

I downloaded and installed AHK in the default way (express installation), should I have some custom settings? Also, my OS is Windows 10.

I would really appreciate your help. Thanks.
User avatar
mikeyww
Posts: 27146
Joined: 09 Sep 2014, 18:38

Re: My scripts stop working randomly

05 May 2024, 21:36

Since the script "randomly stops", I think that an initial goal would be to fix this specific issue. Test the following script in Notepad. It is the same as the earlier one but with sounds removed. Do not change the script or add any code to it. Close other scripts before testing.

Code: Select all

#Requires AutoHotkey v1.1.33.11

j::
SetTimer Fire, 16
Gosub Fire
KeyWait j
Return

j Up::
SetTimer Fire, Off
Return

Fire:
SetKeyDelay 25, 25
SendEvent j
Return
Knowing whether this script works in Notepad is a helpful starting point. If this script works in Notepad, you can test it in your game and then check the KeyHistory.

The other commands that you mentioned do not seem important at the moment.

AutoHotkey does not have settings per se. That's a good feature!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 32 guests