开发者

Is there any way to turn on/off Num, Caps and Scroll Lock lights?

开发者 https://www.devze.com 2023-03-02 19:25 出处:网络
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 disc开发者_运维知识库o.Try

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 disc开发者_运维知识库o.


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.


Probably through JNI and a c method. Check some discussions here:

http://www.autohotkey.com/forum/viewtopic.php?p=50596#50596

http://www.autohotkey.com/forum/viewtopic.php?t=8372


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消