Cg2916
Cg2916

Reputation: 1117

Trouble with Key Bindings

I am creating a Pong clone, and I am trying to use KeyBindings. This works:

getInputMap().put(KeyStroke.getKeyStroke("F2"),"leftup");
        getActionMap().put("leftup", new AbstractAction() {
            private static final long serialVersionUID = -7625435800213244316L;

            public void actionPerformed(ActionEvent e) {
                System.out.println("Yay");
            }
        });

But not this:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.ACTION_EVENT),"leftup");
        getActionMap().put("leftup", new AbstractAction() {
            private static final long serialVersionUID = -7625435800213244316L;

            public void actionPerformed(ActionEvent e) {
                System.out.println("Yay");
            }
        });

Upvotes: 1

Views: 234

Answers (1)

Polynomial
Polynomial

Reputation: 28316

According to the Java docs, there's no overload of getKeyStroke that fits KeyEvent, Event.

Pretty sure

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.ACTION_EVENT),"leftup");

should be

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W),"leftup");

Upvotes: 2

Related Questions