0

我正在使用 LWJGL,当我按住一个键(比如在 word 中按住一个字母键)时,我想快速发生一个事件。

这是我的尝试:

while(Keyboard.next())
{
    if (Keyboard.getEventKeyState())
    {
        if (Keyboard.isKeyDown(Keyboard.KEY_UP)) 
        {
            i += 5.0f;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) 
        {
            i -= 1.0f;
        }
    }
}
4

2 回答 2

0

if (Keyboard.getEventKeyState())仅在按下键时运行。

对于按住,使用布尔值/整数来记录你的游戏循环应该增加还是减少i

于 2012-10-11T00:20:03.820 回答
0

我在按下时使用机器人和线程回答了我自己的问题:

        if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
        {
            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_DOWN);
            zpos -= 0.1f;
            Thread.sleep(100);
            robot.keyRelease(KeyEvent.VK_DOWN);
        }
于 2012-10-16T14:54:05.650 回答