Page 1 of 1

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

Posted: 18 Mar 2023, 17:26
by Xrudo
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.

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

Posted: 19 Mar 2023, 04:33
by off
Hi @Xrudo
You may want take a look at https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm

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

Posted: 19 Mar 2023, 11:54
by Xrudo
@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?

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

Posted: 19 Mar 2023, 22:42
by off
@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

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

Posted: 20 Mar 2023, 13:09
by Xrudo
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} 
}

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

Posted: 20 Mar 2023, 14:06
by boiler
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.

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

Posted: 20 Mar 2023, 14:42
by Xrudo
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?

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

Posted: 20 Mar 2023, 14:50
by boiler
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.

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

Posted: 20 Mar 2023, 14:56
by Xrudo
@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?

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

Posted: 20 Mar 2023, 15:04
by boiler
I don't know. Maybe someone else can answer that.

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

Posted: 20 Mar 2023, 20:18
by off
@Xrudo
I use this script sometimes
viewtopic.php?t=5472