Retrieving on-screen keyboard input with libgdx

I am trying to write a game, and if they do something, it will launch the on-screen keyboard. Then, if they touch several keys, the game will change the scene to the bonus level. I am currently using libgdx and it works fine on the desktop version with a real keyboard. I can not get it to work on the Android version.

In the rendering 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 thing is to show the keyboard. That's what it is. However, when I try to detect a keystroke:

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

I never get true value. No matter what key or value. How to detect keystrokes on an Android on-screen keyboard in libGDX?

+4
source share
1 answer

Gdx.input.isKeyPressed checks the status of the keyboard, so it will be true only when the key is actually held. This is probably not a condition that an onscreen keyboard can even report.

Switching to InputProcessor makes each keyboard event delivered as a separate event.

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

+2
source

Source: https://habr.com/ru/post/1446037/


All Articles