3

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
daGrevis
  • 21,014
  • 37
  • 100
  • 139

3 Answers3

7

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.

Bala R
  • 107,317
  • 23
  • 199
  • 210
0

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

Aleadam
  • 40,203
  • 9
  • 86
  • 108
-1

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.

Community
  • 1
  • 1
Luis Miguel Serrano
  • 5,029
  • 2
  • 41
  • 41