Jump to content

[1.7.2] Check If Player Is Typing [SOLVED]


TLHPoE

Recommended Posts

If you mean typing anything (including movement keys) then you can of course just use key input event handling.  You might also be able to be clever and check for chat entry and exit, but might be a bit tough to ensure you're in sync with when it is actually in chat.

 

I think the best way might be to detect when the chat gui is open.  The GuiNewChat class has a public method called isChatOpen().  There is only one GuiNewChat instance per client (it is persistent because it has to keep track of all the previous chat entries) which can be retrieved with the public method called getChatGui() in the GuiIngame class.  The GuiIngame class is extended by Forge and there seems to be one public instance in the Minecraft class.

 

So...I think (haven't tried it) that you can use (only on client side!)

Minecraft.getMinecraft().ingameGUI.getChatGUI().getChatOpen() 

to check if chat is being entered.  It should be true when open.  You could check it every tick I guess in some sort of tick method or event handler, or you could check during key input event to save some processing burden. EDIT: I just tried this and you have to use a tick handler -- key input events actually DON'T fire while chat interface is up.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Okay, I tried this out and it works well.  Subscribe to rendertick event on FML bus and used following method:

	@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(RenderTickEvent event)
{
	// DEBUG
	if (Minecraft.getMinecraft().ingameGUI.getChatGUI().getChatOpen())
	{
		System.out.println("Chat is open");
	}

}

And it printed "Chat is open" over and over on console when I either opened the command line with "/" or a chat with "T".  It stopped printing to the console when I pressed ESC to get out of chat.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.