When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Ask gaming related questions (AHK v1.1 and older)
Xrudo
Posts: 5
Joined: 18 Mar 2023, 17:09

When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by Xrudo » 18 Mar 2023, 17:26

So I would like to make a code that when pressing a hotkey can detect if in Minecraft my inventory or options are open. If it's not open: it completes a function. If it's open: close the inventory (Esc) and complete a function.

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by off » 19 Mar 2023, 04:33

Hi @Xrudo
You may want take a look at https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Xrudo
Posts: 5
Joined: 18 Mar 2023, 17:09

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by Xrudo » 19 Mar 2023, 11:54

@off

Hi, This could actually work, but is there a buffer time while it finds the image, if so how long is it? The acceptable delay could be around or less than 100ms. And does it work on fullscreen games without any frame drops?

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by off » 19 Mar 2023, 22:42

@Xrudo
Depends on how large your image is..
For minecraft inventory, you can just have a 2x2 crafting grid for ImageSearch, as long the size is same as the original it will work.

About the delay, you can test it yourself. If you already created a script and have problem.. Feel free posting it here
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Xrudo
Posts: 5
Joined: 18 Mar 2023, 17:09

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by Xrudo » 20 Mar 2023, 13:09

Hi,@off
I wrote the code and it displays that the first else (at line 9) has no matching if, and I don't know why, can you help me?

Code: Select all

GoSpectator() {
  idx := GetActiveInstanceNum()
  CoordMode Pixel 
ImageSearch, FoundX, FoundY, 976, 404, 1053, 481, E:\Program\Speedrun\ImageSearch\Inventory.png
if (ErrorLevel = 2)
    Send,{F3 down} 
    Send,n
    Send,{F3 up}.
else if (ErrorLevel = 1)
    Send,{F3 down} 
    Send,n
    Send,{F3 up}
else 
    Send,{Esc}
    Send,{F3 down} 
    Send,n
    Send,{F3 up} 
}

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

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by boiler » 20 Mar 2023, 14:06

That shouldn’t even run without an error because you have an “else” with no matching “if”. Indenting doesn’t group blocks of code in AHK. Braces { } do.

Xrudo
Posts: 5
Joined: 18 Mar 2023, 17:09

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by Xrudo » 20 Mar 2023, 14:42

Hi, @boiler
Thank you for the help, fixed that problem, but now it couldn't find the image I wanted it to find and gave the ErrorLevel = 1 even tho it was on the screen. could the problem be that the game was in full screen?

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

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by boiler » 20 Mar 2023, 14:50

There are several potential issues. One could be that your reference image has some background in it that changes so it's not finding it. It could be that it's rendered differently than when you captured the image. The first thing to try is to take a screen capture of the screen where it should be found and just make sure you can find it on that screen capture. If you post your reference image and the screenshot, we might be able to spot a problem.

Xrudo
Posts: 5
Joined: 18 Mar 2023, 17:09

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by Xrudo » 20 Mar 2023, 14:56

@boiler
I was right, the problem is the full screen, when I turned it off it worked perfectly but I don't want to play with borders so is there a way to make it work on full screen Minecraft?

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

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by boiler » 20 Mar 2023, 15:04

I don't know. Maybe someone else can answer that.

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: When pressing a hotkey, detect if my inventory or options are open in Minecraft.

Post by off » 20 Mar 2023, 20:18

@Xrudo
I use this script sometimes
viewtopic.php?t=5472
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Post Reply

Return to “Gaming Help (v1)”