I'm trying to bind the left alt key and the right shift key in a JPanel. Here's my code:
int RIGHT_SHIFT = KeyEvent.VK_SHIFT; int LEFT_ALT = KeyEvent.VK_ALT; // right shift (move current item right) inputMap.put(KeyStroke.getKeyStroke(RIGHT_SHIFT, 0, false), "right_shift"); actionMap.put("right_shift", new InputProcessor(PRESSED, RIGHT_SHIFT)); // left alt (move current item left) inputMap.put(KeyStroke.getKeyStroke(LEFT_ALT, 0, false), "left_alt"); actionMap.put("left_alt", new InputProcessor(PRESSED, LEFT_ALT));
Neither alt keys nor the shift keys have the effect I want.
But if I change my code to this:
int RIGHT_SHIFT = KeyEvent.VK_S; int LEFT_ALT = KeyEvent.VK_A; // right shift (move current item right) inputMap.put(KeyStroke.getKeyStroke(RIGHT_SHIFT, 0, false), "right_shift"); actionMap.put("right_shift", new InputProcessor(PRESSED, RIGHT_SHIFT)); // left alt (move current item left) inputMap.put(KeyStroke.getKeyStroke(LEFT_ALT, 0, false), "left_alt"); actionMap.put("left_alt", new InputProcessor(PRESSED, LEFT_ALT));
It works.
So what does VK_ALT and VK_SHIFT refer to? Why does using VK_S and VK_A make the s and a keys effective but using the VK_ALT and VK_SHIFT doesn't make the alt and shift keys effective? What would one use if he wanted to use the alt and shift keys - and specifically the left alt key and the right shift key?