如何判断按下了哪个SHIFT键?

在我的游戏中,我希望能够使用右移和左移键来实现不同的function。 在Java(或其他语言)中,有没有办法区分这两者?

KeyEvent类只有VK_SHIFT,它对应左右Shift键。 与ControlAltEnter等相同

我主要担心的是有人可能会用两根手指同时快速按下两个按键,从而获得不公平的优势。 我应该关注这件事吗?

我找到了一个包含Java WebStart示例和源代码的Java教程。 看起来赢家是KeyEvent.getKeyLocation()

  • KeyEvent.KEY_LOCATION_STANDARD
  • KeyEvent.KEY_LOCATION_LEFT
  • KeyEvent.KEY_LOCATION_RIGHT
  • KeyEvent.KEY_LOCATION_NUMPAD
  • KeyEvent.KEY_LOCATION_UNKNOWN

参考文献:

关键监听器演示和源代码

KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar, int keyLocation) 

方法:

  int getKeyLocation() 

返回发起此键事件的键的位置。

 public static final int KEY_LOCATION_LEFT A constant indicating that the key pressed or released is in the left key location (there is more than one possible location for this key). Example: the left shift key. 

您还可以查看jinput,这是一个可以直接访问所有输入设备的库,为您提供更多控制。 如果您决定在游戏中使用LWJGL,那么它已经配备了jinput。