I definitely donβt see the point, seeing how keyPressed() , keyReleased() and keyTyped() called whenever every key is pressed.
You also said that storage states do not work. Have you tried something like this?
boolean[] keys = new boolean[222]; // 222 is the highest keyCode value i know public void keyPressed(KeyEvent e) { keys[e.getKeyCode()] = true; } public void keyReleased(KeyEvent e) { keys[e.getKeyCode()] = false; } // True is pressed, False is released public boolean getState(int keyCode) { return keys[keyCode]; }
This is truly the smartest way to check the status of a "real-time" key. You cannot just ask the computer about the status of a key without using a Listener . Perhaps more detailed information about what you need for a "real time" state will help you better respond.
source share