6

For some reason unknown to me, when I use Buttons.LEFT with an event handler, nothing happens. Here is my code:

if (Gdx.input.isKeyPressed(Buttons.LEFT)) {
 System.out.println("Mouse clicked!");
}

If I do, say, Keys.LEFT, or justTouched(), the message prints, but not when I do Buttons.LEFT. And yes, I'm 100% I'm pressing my mouse button, and that it works correctly. ;)

Thank you!

asked Jan 11, 2013 at 2:57

1 Answer 1

11

This is because Gdx.input.isKeyPressed() is for Keyboard input. If you want mouse button input you should be doing

if (Gdx.input.isButtonPressed(Buttons.LEFT)){
 System.out.println("Mouse clicked!");
}

Buttons and Keys are different classes, and as such have matching methods in input. Explore the Input API Javadocs of theirs a bit more, it's helped me quite a lot.

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Input.html

answered Jan 11, 2013 at 3:05
Sign up to request clarification or add additional context in comments.

1 Comment

That would make a lot of sense! I completely overlooked that. Thanks a lot.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.