<bdo id='AZ8oi'></bdo><ul id='AZ8oi'></ul>

      <legend id='AZ8oi'><style id='AZ8oi'><dir id='AZ8oi'><q id='AZ8oi'></q></dir></style></legend>

      <i id='AZ8oi'><tr id='AZ8oi'><dt id='AZ8oi'><q id='AZ8oi'><span id='AZ8oi'><b id='AZ8oi'><form id='AZ8oi'><ins id='AZ8oi'></ins><ul id='AZ8oi'></ul><sub id='AZ8oi'></sub></form><legend id='AZ8oi'></legend><bdo id='AZ8oi'><pre id='AZ8oi'><center id='AZ8oi'></center></pre></bdo></b><th id='AZ8oi'></th></span></q></dt></tr></i><div id='AZ8oi'><tfoot id='AZ8oi'></tfoot><dl id='AZ8oi'><fieldset id='AZ8oi'></fieldset></dl></div>

      <small id='AZ8oi'></small><noframes id='AZ8oi'>

    1. <tfoot id='AZ8oi'></tfoot>

    2. 获取按键代码以及按键修饰符

      时间:2023-07-28
        <legend id='iCesT'><style id='iCesT'><dir id='iCesT'><q id='iCesT'></q></dir></style></legend>

          • <small id='iCesT'></small><noframes id='iCesT'>

              <tbody id='iCesT'></tbody>

          • <tfoot id='iCesT'></tfoot>
          • <i id='iCesT'><tr id='iCesT'><dt id='iCesT'><q id='iCesT'><span id='iCesT'><b id='iCesT'><form id='iCesT'><ins id='iCesT'></ins><ul id='iCesT'></ul><sub id='iCesT'></sub></form><legend id='iCesT'></legend><bdo id='iCesT'><pre id='iCesT'><center id='iCesT'></center></pre></bdo></b><th id='iCesT'></th></span></q></dt></tr></i><div id='iCesT'><tfoot id='iCesT'></tfoot><dl id='iCesT'><fieldset id='iCesT'></fieldset></dl></div>
                <bdo id='iCesT'></bdo><ul id='iCesT'></ul>
                本文介绍了获取按键代码以及按键修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                当用户按下组合键时,我需要获取键的代码以及哪些修饰键(CtrlAltShift 等)当前被按下,并据此选择适当的反应.有比以下更清洁的方法吗?(使用 InputProcessor#keyDown):

                When a user presses a key combination, I need to get key's code and which modifier keys (Ctrl, Alt, Shift etc) are currently pressed, and choose an appropriate reaction based on that. Is there a cleaner way to do this than the following? (using InputProcessor#keyDown):

                public boolean keyDown(int keycode) {
                      boolean ctrl, alt, shift, ...;
                      if (Gdx.input.isKeyPressed(Input.Keys.LEFT_SHIFT) || Gdx.input.isKeyPressed(Input.Keys.RIGHT_SHIFT)) {
                            shift = true;
                      } else if (/* same for ctrl */) {
                          ctrl = true;
                      } else  /* same for other modifiers */ {
                          //...
                      }
                      // Finally, choose an action based on the key combination pressed
                      if (shift && keycode == Input.Keys.A) {
                          // What to do if Shift+A is pressed
                      } else if (/* and so on */) {
                          //...     
                      }
                }
                

                我看到有 Input.Keys.META_* 位掩码,这可能是我需要的,但我没有找到任何关于如何使用这些位掩码的示例.

                I see there are Input.Keys.META_* bitmasks, which are probably what I need, but I haven't found any example on how to use those.

                推荐答案

                您可以使用 keyDown() 方法来检测是否按下了 shift(或任何其他修饰键)以及 keyUp() 方法是否再次释放:

                You could use the keyDown() method to detect whether the shift (or any other modifier key) is pressed and the keyUp() method whether it is released again:

                class MyInputProcesses extends InputProcesses {
                  boolean shift = false;
                  // etc...
                
                  public boolean keyDown(int keycode) {
                    switch(keycode) {
                      case Input.Keys.LEFT_SHIFT :
                      case Input.Keys.RIGHT_SHIFT:
                        shift = true;
                        break;
                      case Input.Keys.A:
                        if(shift) {
                          // Do something if Shift+A is pressed
                        }
                        break;
                    }
                    // etc...
                  }
                
                  public boolean keyUp(int keycode) {
                    switch(keycode) {
                      case Input.Keys.LEFT_SHIFT :
                      case Input.Keys.RIGHT_SHIFT:
                        shift = false;
                        break;
                      // etc...
                    }
                  }
                }
                

                该方法可以防止您询问修饰键的状态,并且更容易修改这些键的触发器(例如,只接受左移).

                The approach prevents you asking the states of the modifier keys and it is easier to modify the triggers for these keys (e.g. only accept the left shift).

                我猜这个解决方案是否更好/更好是个人喜好.我怀疑这会更快(明显).

                Whether this solution is better/nicer is of personal preference I guess. I doubt it that this will be any (noticeable) faster.

                这篇关于获取按键代码以及按键修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 SpriteBatch 时的 LibGDX 模板缓冲区 下一篇:如何使用 libgdx 渲染表情符号

                相关文章

                最新文章

                <tfoot id='9ysW7'></tfoot>
                  <i id='9ysW7'><tr id='9ysW7'><dt id='9ysW7'><q id='9ysW7'><span id='9ysW7'><b id='9ysW7'><form id='9ysW7'><ins id='9ysW7'></ins><ul id='9ysW7'></ul><sub id='9ysW7'></sub></form><legend id='9ysW7'></legend><bdo id='9ysW7'><pre id='9ysW7'><center id='9ysW7'></center></pre></bdo></b><th id='9ysW7'></th></span></q></dt></tr></i><div id='9ysW7'><tfoot id='9ysW7'></tfoot><dl id='9ysW7'><fieldset id='9ysW7'></fieldset></dl></div>
                  <legend id='9ysW7'><style id='9ysW7'><dir id='9ysW7'><q id='9ysW7'></q></dir></style></legend>

                    <small id='9ysW7'></small><noframes id='9ysW7'>

                    • <bdo id='9ysW7'></bdo><ul id='9ysW7'></ul>