如何判断按下哪个SHIFT键?

时间:2009-06-13 23:29:33

标签: java keyboard

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

KeyEvent类只有VK_SHIFT,它对应左右移位键。与 Control Alt Enter 等相同

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

3 个答案:

答案 0 :(得分:18)

我找到了一个包含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

参考文献:

Key Listener Demo and Source Code

答案 1 :(得分:1)

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.

答案 2 :(得分:0)

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