0
\$\begingroup\$

I am trying to make a class which will handle all of my inputs, however Keyboard.next() isn't returning true. Here is my code.

    while(Keyboard.next()) {
        if(Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
            if (Keyboard.getEventKeyState()) {
                System.out.println("Pressed");
            }else {
                System.out.println("Released");
            }               
        }
    }

When I removed the while loop, it infinitely outputs Pressed/Released so I know that part of the code is working. Is there something that I am missing to make this fully work?

\$\endgroup\$
-2
\$\begingroup\$

This code must be in the update method, if not it won't work. So you cannot seperate it in another class.

The meanings of the single methods, next() and getEventKeyState() are in the lwjgl docs, if you want more information.

while (Keyboard.next()) {
   if (Keyboard.getEventKeyState()) {
   if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
        System.out.println("Pressed");
   }
   }
 }
\$\endgroup\$
  • 3
    \$\begingroup\$ You should expand this answer with why this works. What's it doing? What problem is it solving? \$\endgroup\$ – MichaelHouse May 1 '14 at 21:14
  • \$\begingroup\$ I edited it. Hope it is good enough and helps. :) \$\endgroup\$ – Kronos May 2 '14 at 10:35
  • \$\begingroup\$ It's wrong and telling them to "go look it up" doesn't make for a good answer. You're not even giving a little bit of information, obviously if they wanted to know more before you said to "go look it up" they would have looked in the docs, so your statement doesn't add much. Further, you can separate the code into another class, making a keyboard object and then populating it in the update method is totally valid. \$\endgroup\$ – MichaelHouse May 2 '14 at 14:40
  • \$\begingroup\$ I figured out the problem in the end. I wasn't calling the function properly. Sorry for not clarifying that. \$\endgroup\$ – Brian May 2 '14 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.