How to run a minecraft script in the back ground

Ask gaming related questions (AHK v1.1 and older)
TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

How to run a minecraft script in the back ground

Post by TheWildHuli » 25 Jan 2023, 15:45

hello,
I just wanted to ask how to run a script, (with basic commands like send or click) In the background on a certain window. I only want the commands to be inputed on that window and I don't want it to do anything but on that window.

Thanks

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 25 Jan 2023, 21:48

Welcome to this AutoHotkey forum!

Have a look at :arrow: ControlSend and ControlClick. The forum also has hundreds or thousands of examples.

I have cited the v2 syntax, but v1 is also available if you want something older!

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 27 Jan 2023, 14:42

Thank you so much!

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 29 Jan 2023, 19:16

hello,

I just came up with this script with the ContronClick thing to auto matically send a click to a application with a pid of 26732. For some reason when I try to do it I does not send the click through.(I am trying to send it to minecraft)

heres my code:

^r::

ControlClick ,ahk_pid #26732

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 29 Jan 2023, 19:47

Well, AutoHotkey does require following the syntax provided! Here is a good example to model.

https://www.autohotkey.com/docs/v2/lib/ControlClick.htm#ExBasic

Here is an example of how to use the Return command.

https://www.autohotkey.com/docs/v1/Hotkeys.htm#Intro

I generally avoid PIDs when possible, because they change and can be tricky to use. Try something simple as a start, maybe a process name as part of a proper WinTitle. Hard-coding a PID into your script will nearly always fail. Actually, I am unaware of any circumstance when it would succeed (other than randomly, or when you checked the PID manually during one program session), but I suppose that someone on this forum knows how to set a PID!

If you search the forum for the name of your game, you may find examples of how others have approached the same issue.

As far as I know, a PID is a number and so does not have #.

Code: Select all

#Requires AutoHotkey v2.0
MsgBox 'PID example:`n`n' WinGetPID("A"), 'PID', 64
Running Window Spy will show you additional examples of the PID specification for a WinTitle.

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 30 Jan 2023, 20:48

I just chose PID because I saw it on the window spy. Can you recommend which one is the easiest? I need to be able to distinguish the window from others that are named the same thing. Also if possible could you provide an example with using the ControlClick. I just want to see how it works because I can't find any examples that use a way to distiniguish the applications.

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 30 Jan 2023, 21:10

When you think about the two windows with the same window title, same window class, and same process name, what is your description of how you identify the window that you would like to target? Without AutoHotkey, how do you identify the right window yourself?

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to run a minecraft script in the back ground

Post by DuckingQuack » 31 Jan 2023, 11:25

@TheWildHuli
If you don’t mind, could you tell me what sort of tasks you intend to automate in Minecraft? (i.e. continuously break a block from a generator while standing still)
Also, how many minimized windows are you interested in sending commands to? As that will determine the methods available for identifying the window(s).
Some more questions: what version of ahk are you using? Do you have a script you’re working on, functional or not?
Best of Luck,
The Duck

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 31 Jan 2023, 14:29

I am trying to automate a raid farm. This involves moving around, clicking, pausing, and then repeating the process. I am interested in sending commands to one window but it is labeled the same as another because it is my alt on Minecraft. I am not entirely sure what version I have but I'll update to whatever version I have to. I already have the script to automate the process but I just want it to be able to run on a minimized window.

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 31 Jan 2023, 14:58

That is all OK, though the question that I asked is not actually answered.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to run a minecraft script in the back ground

Post by DuckingQuack » 31 Jan 2023, 15:21

@TheWildHuli If that’s the case, then mikeyww has already given you all the tools you need to succeed. There’s nothing I can assist with.
Best of Luck,
The Duck

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 01 Feb 2023, 14:21

Sorry Mikeyww,

The way I distinguish it is that on the page itself, there is a visual indicator that it is different. When I am on one Minecraft account I can see one name and when I am on another I see a different name. The only thing that I am sure of is that the winTitle is the same.

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 01 Feb 2023, 20:06

If you want to detect a specific image, you could try it with :arrow: ImageSearch.

An alternative is that you use your AHK script to run Minecraft. If you do it that way, you will know which window you need to target.

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 01 Feb 2023, 23:48

I think the running minecraft with ahk will be easier. Ill look into that but just to make sure are the only ways of distinguishing a window from the Window spy. When I am on the two minecrafts the ahk_class is the same the ahk_exe is thhe same the wintitle is the same but the ahk_pid is different.

Thanks

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 02 Feb 2023, 09:32

You would need some way to distinguish the windows, and the PID and HWND will change with each run. Nonetheless, using AHK to run Minecraft is a good way to go. You can then get the HWND and use it to target your specific window.

Code: Select all

; This script runs multiple program instances, and activates one of them
#Requires AutoHotkey v2.0
app      := A_WinDir '\System32\notepad.exe'
winTitle := 'ahk_exe' app
win      := []
GroupAdd 'appGroup', winTitle

F3:: {                                                   ; F3 = Run app
 Try WinMinimize 'appGroup'
 Run app
 WinWaitActive(winTitle,, 9) && win.Push(WinActive("A")) ; Store HWND
}

F4:: {                                                   ; F4 = Activate first window in the group
 For each, hWnd in win
  Try WinActivate(hWnd)
 Until WinExist(hWnd)
}

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to run a minecraft script in the back ground

Post by DuckingQuack » 02 Feb 2023, 10:10

@TheWildHuli Hey! I tried messing with Minecraft last night and had zero luck sending controls to the widow. So I was wondering what version you are running. Bedrock or Java?
Best of Luck,
The Duck

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 02 Feb 2023, 23:53

@DuckingQuack

I am Using Java

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: How to run a minecraft script in the back ground

Post by DuckingQuack » 03 Feb 2023, 05:45

Ah… that sucks for me, bedrock is much more challenging to add macros to. I hope you achieve your goals.
Best of Luck,
The Duck

TheWildHuli
Posts: 12
Joined: 25 Jan 2023, 15:26

Re: How to run a minecraft script in the back ground

Post by TheWildHuli » 03 Feb 2023, 14:17

Mikeyww,
The way miencraft is launched is you initially open up the minecraft launcher and then launch it from within the app. Ill try to look for a way to cut out the launcher by finding a shortcut of something but if I can't is there a way to still do it?

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

Re: How to run a minecraft script in the back ground

Post by mikeyww » 03 Feb 2023, 15:19

I do not use Minecraft, but if AHK runs the program, then yes, you should be able to get the window ID from what is spawned, even if there is an intervening step. Identifying the WinTitle information from Window Spy may be helpful in determining how to identify the right window.

Post Reply

Return to “Gaming Help (v1)”