【问题标题】:Pressing and Holding a key in LWJGL在 LWJGL 中按住一个键
【发布时间】:2012-09-23 20:13:30
【问题描述】:

我正在使用 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;
        }
    }
}

【问题讨论】:

    标签: java keyboard key lwjgl tapandhold


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

              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);
              }
      

      【讨论】:

        猜你喜欢
        • 2013-04-10
        • 2021-12-04
        • 2017-04-30
        • 1970-01-01
        • 1970-01-01
        • 2014-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多