0

How to make small vk letters like case VK_k instead of VK_K? using Switch Case Thanks

public void onKeyPressed(KeyEvent e){

    switch(e.getKeyCode()){

    case VK_K: 
               moveDirection=1;
               moveAmount = Double.POSITIVE_INFINITY;

             break;

    case VK_L: moveDirection=-1;
               moveAmount = Double.POSITIVE_INFINITY;
             break;

    case VK_H: turnDirection=-1;
             break;

    case VK_J: turnDirection=1;
             break;
    case VK_SPACE: firePower = 1;
            break;

    }

}
DavidS
  • 5,022
  • 2
  • 28
  • 55
NL_FH
  • 3
  • 4

1 Answers1

4

You should read the description of KeyEvent fully - it contains the answer:

Virtual key codes are used to report which keyboard key has been pressed, rather than a character generated by the combination of one or more keystrokes (such as "A", which comes from shift and "a").

Conclusion: Your keyboard has only one K key - hence there is only the constant VK_K. What other keys (shift, alt, ctrl, ..) you are pressing at the same time does not change the key code you get.

Robert
  • 39,162
  • 17
  • 99
  • 152