Need help with inactive window not running script

Ask gaming related questions (AHK v1.1 and older)
Big_Brother1984
Posts: 1
Joined: 30 Nov 2022, 18:32

Need help with inactive window not running script

Post by Big_Brother1984 » 30 Nov 2022, 19:00

Hi, this is my first forum post so please correct me if I made in an error in the process of posting this. The code I have here runs perfectly while my active window is Minecraft, but as soon as I press Alt + Tab to change windows, the script just stops running. I am running two Minecraft games simultaneously, and I have it working in only one game, which is what I wanted. I want to play on one account while the other is running the script. But every time I change out of the window, it pauses. I've looked on the forums to posts about how to make AHK run in most games, tried all those methods, but they didn't work. And the script I have here was copied from a kind stranger helping someone else with their script. That person said it worked for them, so I don't know why it isn't working for me. And the strange thing is, when I press Esc, my Minecraft game menu opens, but when I press Esc the script just keeps going, which means Esc::ExitApp isn't working for some reason. I don't know why Alt Tab is pausing it and not Esc. Please be patient with me because I have absolutely zero prior knowledge about coding. I've spent over 10 hours experimenting with different solutions, all of them failing.

Code: Select all

#NoEnv
DetectHiddenWindows, On

ClassName = LWJGL
CurrentID =

WinGet, GameList, List, ahk_class %ClassName%
if (GameList = 0)
{
	MsgBox, 48, Game Not Found, Game window not found. Please Relaunch the game and try again.
	ExitApp
}
else if (GameList = 1)
{
	Loop, %GameList%
		CurrentID := GameList%A_Index%	
}
else if (GameList >= 2)
{
	MsgBox, 64, Multiple Found, More then 1 game running.`nThe game windows will be marked as active, bringing them to the front.`nFollow the prompts and confirm which window to link the script to.
	Loop, %GameList%
	{
		CurrentID := GameList%A_Index%
		WinActivate, ahk_id %CurrentID%
		MsgBox, 36, Confirm Game Link, Is the current activated window the one to link to?`n ID = %CurrentID%
		IfMsgBox Yes
			break
		else
			CurrentID =
	}
}
if (CurrentID = "")
{
	MsgBox, 48, ID Not Selected, GameID not selected during selection process. Please try again.`nExiting script.
	ExitApp
}
else
{
	GameID := CurrentID
}

While (WinExist("ahk_id " GameID) != 0)
{

	=::
	Click, D
	Loop {
		ControlClick, ahk_id %GameID%
		ControlSend,, {s down}, ahk_id %GameID%
 		Sleep, 23000
 		ControlSend,, {s up}, ahk_id %GameID%
		Sleep, 500
		ControlSend,, {d down}, ahk_id %GameID%
 		Sleep, 23000
 		ControlSend,, {d up}, ahk_id %GameID%
		Sleep, 240
	}

}

MsgBox, 48, Game Not Found, The game window has either been closed or for whatever reason is not found. Please try again.
ExitApp
Esc::ExitApp

[Mod actions: Moved topic to "Gaming" and added [code][/code] tags. Please use them yourself when posting code.]

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Need help with inactive window not running script

Post by boiler » 30 Nov 2022, 19:07

Big_Brother1984 wrote: Hi, this is my first forum post so please correct me if I made in an error in the process of posting this.
Welcome, and thanks for looking for inquiring about how best to post. See the comments added to the bottom of your post.

Post Reply

Return to “Gaming Help (v1)”