public void keyStrokeActions(){
screen.setFocusable(true);
screen.getInputMap().put(KeyStroke.getKeyStroke("pressed SPACE"),"attackAction");
screen.getActionMap().put("attackAction",attackAction);
screen.getInputMap().put(KeyStroke.getKeyStroke("pressed P"),"pauseAction");
screen.getActionMap().put("pauseAction",pauseAction);
}
I am trying to make this work, as you can see it's a simple keyStroking where screen's a JPanel. The actions attackAction and pauseAction are defined before as global variables.
In windows everything works perfectly, however in mac it doesn't. No matter the key I press, it doesn't react. I also tried
screen.getInputMap().put(KeyStroke.getKeyStroke(' ',0),"attackAction");
and
screen.getInputMap().put(KeyStroke.getKeyStroke(' '),"attackAction");
But I couldn't make it work. Not with ' ' or 'P' or any other sort of char. Anyone could bring some light?
Thanks, Sergi.
After a lot of time working on it, I found out that if it worked on Mac it didn't on windows, and if it worked in windows it didn't on Mac. So, basically, java's multi-platform as long as the virtual machine's fine with it.