I think you can print in the main thread while checking on a boolean (lets say "isKeyPressed" which will be initially false) in while loop whenever a key pressed in the key listener you will set the boolean flag to true which will prevent the main thread from printing and when key released is fired, you wil set the boolean flag to false again to resume Printing
in main method
while(!isKeyPressed){
your logic / printing
}
in your keypressed listener
public void keyPressed(KeyEvent e) {
isKeyPressed = true;
}
in your keyReleased listener
public void keyReleased(KeyEvent e) {
isKeyPressed = false;
}
Hope that will help you.