Java - GetLockingState() won't update

荒凉一梦 提交于 2020-01-03 02:22:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!