I'm trying to key bind the a
and d
keys to make a character move left and right, but the actions only happen once when you press the keys. How can I modify this code to make it do the event while a
or d
is being held down?
p.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0),"up");
p.getActionMap().put("up", new UpAction());
p.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0), "left");
p.getActionMap().put("left", new LeftAction());
p.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0), "right");
p.getActionMap().put("right", new RightAction());
p.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),"quit");
p.getActionMap().put("quit", new StopAction());