There are a lot of "key pressing in Java" questions already here so I did read some of them (Actually got a piece of the code from one). non answer the problem I've been having. I found this code that detects if a key is pressed and also if it's released but I can't get rid of this error
In this case I am testing if the 'W' is pressed
code:
private static boolean IsPressing(String string) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
@Override
public boolean dispatchKeyEvent(KeyEvent ke) {
synchronized (IsKeyPressed.class) {
boolean wPressed;
switch (ke.getID()) {
case KeyEvent.KEY_PRESSED:
if (ke.getKeyCode() == KeyEvent.VK_W) {
wPressed = true;
}
break;
case KeyEvent.KEY_RELEASED:
if (ke.getKeyCode() == KeyEvent.VK_W) {
wPressed = false;
}
break;
}
return false;
}
}
});
return false;
}
}
So basicly in the sixth line (synchronized (IsKeyPressed.class) {) it tels mee that "IsKeyPressed.class cannot be resolved to a type", then I get four eclipse options:
1.Create Class 2.Create Interface 3.Create Enum 4.Fix project
The first three I don't think that help me achieve my goal of detecting if a key is pressed, and the last one doesn't do anything
What am I doing wrong?