title: How can I set up my keybinds in such a way that the character does not pause between inputs?
body: <p>I'm attempting to make a simple bullet hell game and am struggling to make smooth movement mechanics for the character. Here is my current code:</p>
  <pre><code>package bullethell;
  
  import java.awt.BorderLayout;
  import java.awt.EventQueue;
  import java.awt.Image;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyEvent;
  import java.io.File;
  import java.io.IOException;
  
  import javax.imageio.ImageIO;
  import javax.swing.AbstractAction;
  import javax.swing.ActionMap;
  import javax.swing.InputMap;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.KeyStroke;
  import javax.swing.Timer;
  import javax.swing.border.EmptyBorder;
  
  public class GameDisplay extends JFrame {
  
      private static final long serialVersionUID = -2586882806098087146L;
      private JPanel contentPane;
      private GameObject player;
      
      int xDirection = 0;
      int yDirection = 0;
      
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      GameDisplay frame = new GameDisplay();
                      frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      public GameDisplay() throws IOException {
          setUndecorated(true);
          contentPane = new JPanel();
          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
          contentPane.setLayout(new BorderLayout(0, 0));
          setContentPane(contentPane);
          
          setMovementKeys();
          
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setBounds(0, 
                    0, 
                    (int) 500, 
                    (int) 500);
          
          Image sprite = ImageIO.read(new File(&quot;Sprites/Player.png&quot;));
          player = new GameObject(sprite);
          player.setBounds(0, 0, sprite.getWidth(null), sprite.getHeight(null));
          contentPane.add(player);
      }
  
      private void setMovementKeys() {
          
          InputMap in = contentPane.getInputMap();
          ActionMap out = contentPane.getActionMap();
          
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0, false), &quot;w-pressed&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0, true), &quot;w-released&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false), &quot;a-pressed&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, true), &quot;a-released&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0, false), &quot;s-pressed&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0, true), &quot;s-released&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0, false), &quot;d-pressed&quot;);
          in.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0, true), &quot;d-released&quot;);
          
          out.put(&quot;w-pressed&quot;, new MovementKeyAction(0,-10));
          out.put(&quot;w-released&quot;, new MovementKeyAction(0,0));
          out.put(&quot;a-pressed&quot;, new MovementKeyAction(-10,0));
          out.put(&quot;a-released&quot;, new MovementKeyAction(0,0));
          out.put (&quot;s-pressed&quot;, new MovementKeyAction(0,10));
          out.put(&quot;s-released&quot;, new MovementKeyAction(0,0));
          out.put (&quot;d-pressed&quot;, new MovementKeyAction(10,0));
          out.put(&quot;d-released&quot;, new MovementKeyAction(0,0));
          
          Timer timer = new Timer(1, new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  player.setLocation(player.getX() + xDirection, player.getY() + yDirection);
              }
          });
          timer.start();
      }
      
      private class MovementKeyAction extends AbstractAction {
          
          private static final long serialVersionUID = -3671863065039719595L;
          public int x, y;
          
          public MovementKeyAction(int x, int y) {
              this.x = x;
              this.y = y;
          }
          
          @Override
          public void actionPerformed(ActionEvent e) {
              xDirection = x;
              yDirection = y;
          }
          
      }
      
  }
  </code></pre>
  <p>What I am struggling with is modifying this so that there is no delay between inputs of different directions. Here is a gif of what I mean: <a href="https://i.stack.imgur.com/Xy6mT.gif" rel="nofollow noreferrer">https://i.stack.imgur.com/Xy6mT.gif</a></p>
  <p>Any help would be greatly appreciated.</p>