Frage

Is there any way to turn on/off Num, Caps and Scroll Lock lights? It's just for fun and my idea is to do something like disco.

War es hilfreich?

Lösung

Try

Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true);

to set Caps lock On.

Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false);

to set Caps lock Off.

and

boolean isCapsLockOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);

to get current status.

use KeyEvent.VK_NUM_LOCK for num lock.

I have tested this on Windows. I'm not sure about other OSs but I would think it would work.

Andere Tipps

I think you cannot set Caps/Scroll lock's lights independently from their own activation, in a direct way.

You could only achieve such behaviour by programming a keyboard driver of your own (or eventually browsing the web for a driver that might already have been developed to achieve such a behavior), but that is not recommended, and goes way beyond the boundaries of java.

Also, this question is a similar duplicate of Way to turn on keyboard's caps-lock light without actually turning on caps-lock? , even though in this other question that behavior is intended in C#.

However, the issue, impossibility, and the way around it, are the same.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top