KeyUp/KeyDown只被抓到一次

KeyUp/KeyDown is only caught once

我试图在每次按下 BACK 或 SCAPE 键时显示一个对话框。然而事件只被捕获一次,显示对话框但如果我按我的按钮 NO 关闭它,那么它永远不会再次出现,直到我转到另一个屏幕。

这是我捕捉 KeyUp 事件的方式:

@Override
public boolean keyUp(int keycode) {     
    if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {

        dialog.setVisible(true);
    }
    return false;
}

这是我在对话框中的按钮:

    btnNo.addListener(
            new ClickListener() {
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
                {
                    return true;
                }

                public void touchUp(InputEvent event, float x, float y, int pointer, int button){
                    dialog.setVisible(false);
                }
            });

如果你有任何想法,请告诉我...

查看以下网站,他们在 LibGDX http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Dialog.html

中对如何使用 Dialog 进行了清晰的描述

我的问题已通过 Render() 中的以下块代码得到解决:

    if (Gdx.input.isKeyPressed(Keys.BACK) || Gdx.input.isKeyPressed(Keys.ESCAPE)){
        Gdx.input.setCatchBackKey(true);
        dialog.setVisible(true);
    }