Jump to content

[Solved] Show GUI only when key is held


ConsumerJunk

Recommended Posts

Hello, thank you for taking the time to read my question.

 

I have a GUI that I only want to display when a key is being pressed, a lot like a pie menu. I've tried using the Keybinding class and using the Keybinding ::isPressed() method, but when a GUI is open it stops registering as pressed.
How can I go about detecting if a key is pressed inside of a Gui? Preferably a key that is defined by a registered Keybinding so it's configurable.

 

Thank you.

Edited by ConsumerJunk
Link to comment
Share on other sites

Funny how life works sometimes. I spent 3 days stumped on this question, then within 10 minutes of asking it here I found the answer.
To avoid being the person who says they found the answer but fails to mention it in case people in the future have the same question:

 

Inside of the Gui class in the render function (known as func_230430_a_ right now) I run this check, see if the current screen is null, if
it's not null see if the gui is an instance of the custom Gui class, and if it run Minecraft::displayGuiScreen(null). (It probably doesn't need
the checks to see if the screen is null because it the code is running then that means the screen isn't, but I think it's important to have that
edge case, no matter how inconceivable, covered.

InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), someKeybinding.getKey().getKeyCode())
Edited by ConsumerJunk
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.