So I'm learning how to code Java and decided to start with a story-like game. I have a method/function that slows down the dialogue printing so that it looks like typing. However, I can't use scanners to detect next line and stop the code because the scanner isn't constantly active. How would I code this? I know it has something to do with key listeners but I still couldn't figure it out.
Here is the code I'm trying to do:
for(int o = 0; o < diatext.length(); o++){
if(KeyEvent.VK_ENTER == 1) {
speed = 0;
}
Thread.sleep(60);//0.06s pause between characters
System.out.printf("%c", diatext.charAt(o));
}