Jump to content

[1.7.2] [SOLVED] KeyInputEvent


BatHeart

Recommended Posts

My apologies if I am missing something very obvious. It may be that this area has not yet been fully coded for the 1.7.2 forge, in which case I understand.

 

I am trying to update a couple of mods which I had working in 1.6. They used a keyhandler so that I could detect various function key presses to make things appear and disappear on-screen.

 

I realise that the keyhandler has been entirely replaced by an event-driven approach in 1.7. I believe we now have InputEvent which implements Event, and KeyInputEvent and MouseInputEvent which implement InputEvent. I can see that KeyInputEvent does indeed fire when a key is pressed, as expected.

 

However, I am lost when trying to discover which key has been pressed! There is no code within KeyInputEvent, so I have no public getter methods or public variables that I can access.

 

As I said, maybe I am simply trying to use something that hasn't yet been implemented, in which case I apologise for wasting anyone's time.

Link to comment
Share on other sites

In your keyhandler class you need to register your keys. Like:

 

private KeyBinding key_openGUI  = new KeyBinding("key name", Keyboard.KEY_F, "My_Mod_Category");

public static openGUI;

 

public KeyHandlerClass()

{

    ClientRegistry.registerKeyBinding(key_openGUI);

}

 

Then under KeyInputEvent you can check if the key has been pressed.

 

@SubscribeEvent

public void tick(KeyInputEvent event)

{

 

  this.openGUI = false;

 

  if(key_openGUI.func_151468_f())

  {

      this.openGUI = true;

    }

}

 

This is just an example so it might not actually work 100%

Link to comment
Share on other sites

Thank you so much, Skerp!

 

I was doing all of the registration already. That was fine. But you've shown me the method to detect the key-presses and that works perfectly :)

 

I'll be able to put my mods up very soon - probably today.

 

Brilliant news, and thank you again :D

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.