July 23, 201411 yr 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. http://i.imgur.com/NdrFdld.png[/img]
July 23, 201411 yr 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/
July 23, 201411 yr 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.