2009-06-13 29 views
9

En mi juego, quiero poder usar las teclas de mayúsculas derecha e izquierda para diferentes funciones. En Java (u otro idioma), ¿hay alguna manera de distinguir entre esos dos?¿Cómo saber qué tecla SHIFT se presionó?

La clase KeyEvent solo tiene VK_SHIFT, que corresponde a las teclas de mayúsculas izquierda y derecha. Lo mismo con control, Alt, Introduzca, etc.

Mi principal preocupación es que alguien puede ser capaz de usar dos dedos para presionar rápidamente ambas teclas al mismo tiempo, obtener una ventaja injusta. ¿Debería preocuparme por esto?

+5

* vuelve a asignar claves de cambio a j y k * No, nada de qué preocuparse, plan perfecto ... – Shog9

+0

Si el idioma no proporciona esta función (como java lo hace) requerirá contorsiones específicas del sistema operativo ... – dmckee

+0

Por favor especifique el SDK/API que estás usando –

Respuesta

18

Encontré un tutorial de Java que incluye una muestra de Java WebStart y el código fuente. Parece que el ganador es KeyEvent.getKeyLocation()

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

Referencias:

Key Listener Demo and Source Code

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

Método:

int getKeyLocation() 

Devuelve la ubicación de la clave que se originó este evento clave.

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. 
0

También puede echar un vistazo a JInput, una biblioteca que le da acceso directo a todos los dispositivos de entrada, que le da mucho más control. Si decidiste usar LWJGL para tu juego, ya viene con jinput.

Cuestiones relacionadas