4

I am trying to write a game and if they do something it will start up the onscreen keyboard. Then, if they touch a few keys the game will change scenes to a bonus level. I am currently using libgdx and it works great on the desktop version with a real keyboard. I cannot get it to work on the android version.

In the render method:

if (Gdx.input.isTouched()) {
    Vector3 touchPos = new Vector3();
    touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
    camera.unproject(touchPos);

    ...
} else if (touchPos.x > 0 && touchPos.x < 200 
           && touchPos.y > 0 && touchPos.y < 50) {
    Gdx.input.setOnscreenKeyboardVisible(true);
}

This works great. The entire point of this is to get the keyboard to show up. That it does do. However, when I try to detect a key press with:

if (Gdx.input.isKeyPressed(Keys.A)) {
    // Do What I need it to do.
}

I do not get a true value for this ever. No matter what key or value. How do I detect key presses from an on-screen Android keyboard in libGDX?

P.T.
  • 24,557
  • 7
  • 64
  • 95
Keylay
  • 139
  • 2
  • 7
  • 2
    If you setup an `InputProcessor` to get input events (see http://code.google.com/p/libgdx/wiki/InputEvent) do the keyboard changes show up there? – P.T. Nov 15 '12 at 01:42
  • It does. I created a new class and stopped polling they key. Thank you so much for your help. – Keylay Nov 15 '12 at 02:53

1 Answers1

2

Gdx.input.isKeyPressed is polling the state of the keyboard, so it will only be true when the key is actually being held down. That's probably not a state the on-screen keyboard can even report.

Switching to an InputProcessor makes it so each keyboard event is delivered as a distinct event.

See http://code.google.com/p/libgdx/wiki/InputEvent for more details.

P.T.
  • 24,557
  • 7
  • 64
  • 95