Jump to content

Recommended Posts

Posted

I've found you can use KeyBinding#getIsKeyPressed() to reliably check if a key is still held down. isPressed() actually does not do what you think: it checks the press TIME, decrements it, and returns true if it is still greater than zero, whereas getIsKeyPressed simply checks whether the 'pressed' field is true or false.

Posted

Yes, the keybinding will have the state, but the "sad" thing is you'll have to check it every tick if you need to respond to it continuously.  (Until diesieben07s fix to the KeyInputEvent is in place.)

 

To the OP, for now you need to have some method or handler that runs every tick and then do what CoolAlias said to check keybinding key state and maybe store the value in a boolean for use in your code.

 

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

Posted

public class KeyHandler
{
public static final int W= 0;

private static final String[] desc = {"key"};

private static final int[] keyValues = {Keyboard.KEY_W};
private final KeyBinding[] keys;
public KeyHandler() {
	keys = new KeyBinding[desc.length];
	for (int i = 0; i < desc.length; ++i) {
		keys[i] = new KeyBinding("modid.key." + desc[i], keyValues[i], "modid.key.category");
		ClientRegistry.registerKeyBinding(keys[i]);
	}
}

@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
	if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {
		if (keys[W].isPressed()) {
			"Event"
		}
	}
}
}

 

dont forget to register the event!

Coding, Testing, Smiling, Publishing!

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.