问题
Found bug Java Bug
"CAPS" doesn't update. I want it to be actively checking the locking state but it only checks it once and stores true/false in "CAPS" but if you hit caps lock it doesn't change the boolean stored in CAPS.
Thread capsCheck = new Thread(() -> {
while (true) {
boolean CAPS = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
if (CAPS) {
System.out.println("Caps enabled");
} else {
System.out.println("Caps disabled");
}
try {
Thread.sleep(2000);
} catch (Exception e) { }
}
});
来源:https://stackoverflow.com/questions/55021847/java-getlockingstate-wont-update