So in my calculator program, I would like to set up the equals operation where it the mathematical problem could be computed by pressing the enter key (on the main keyboard) or by pressing the enter key (on the numpad). I know the numbers are VK_NUMPAD0 - VK_NUMPAD9, VK_ADD, VK_SUBTRACT, VK_MULTIPLY, VK_DIVIDE. However I can't seem to find one for the enter key. VK_ENTER is for the keyboards enter key. I also looked at KeyEvent.KEY_LOCATION_NUMPAD, but not sure how to add it to my code to get it to work. I have a method called SetupKeyInput() that takes some parameters that adds the key bindings for the inputmap and actionmap.
private void SetupKeyInput(JButton component, int keyStroke, int mask) {
component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(keyStroke, mask), "hmm");
component.getActionMap().put("hmm", new MyButtonEvents(component));
}
So, I can call the function like this
SetupKeyInput(buttonEquals, KeyEvent.VK_ENTER, 0); // Only works for keyboard enter
What am i missing for the numpad enter? I also tried this
SetupKeyInput(buttonEquals, KeyEvent.VK_ENTER, KeyEvent.KEY_LOCATION_NUMPAD);