since default OS provide only key-event-driven support you have to write your own keyboard driver where you can provide methods to poll the key status...
(remember, you don't have hardware pins on your keyboard for each key that can be checked like you're used to do on microcontroller, the keyboard itself handles the states and sends events to the OS, which on its side calls 'interrupts'. these interups are handled by the driver, namely keyboard driver)
Writing a keyboard device driver
you can more easiliy write your own keyboard class that maps all keyevents and can be polled
class KeyboardState extends KeyAdapter{
boolean[] keyState = new boolean[256];
@Override
public void keyPressed (KeyEvent ke){
keyState[ke.keyCode] = true;
}
@Override
public void keyReleased(KeyEvent ke){
keyState[ke.keyCode] = false;
}
public boolean isKeyDown(int keyCode){
return keyState[keyCode];
}
}
this code has been directly written in SO so no validation... don't forget to add you keyboard to the according frame...
(if you're listening to console input let me know - this answer wont fit in then)...