2020-11-27 06:42:16 +01:00
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
public class InputListener implements Runnable {
|
|
|
|
|
|
|
|
private volatile String input = "";
|
|
|
|
private volatile boolean hasNew;
|
|
|
|
private final Scanner in;
|
|
|
|
private boolean stop;
|
2020-11-27 16:38:01 +01:00
|
|
|
private boolean pause;
|
2020-11-27 06:42:16 +01:00
|
|
|
|
|
|
|
public InputListener() {
|
|
|
|
in = new Scanner(System.in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
while(!stop) {
|
2020-11-27 16:38:01 +01:00
|
|
|
if (!pause){
|
|
|
|
input = in.next();
|
|
|
|
hasNew = true;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-11-27 06:42:16 +01:00
|
|
|
}
|
|
|
|
System.out.println("Stopped input listener");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stop() {
|
|
|
|
stop = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getInput() {
|
|
|
|
hasNew = false;
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasNew() {
|
|
|
|
return hasNew;
|
|
|
|
}
|
2020-11-27 16:38:01 +01:00
|
|
|
|
|
|
|
public void pause() {
|
|
|
|
pause = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unpause() {
|
|
|
|
pause = false;
|
|
|
|
}
|
2020-11-27 06:42:16 +01:00
|
|
|
}
|