Try
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true);
to set caps lock on.
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false);
to set the caps off lock.
and
boolean isCapsLockOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
to get the current status.
use KeyEvent.VK_NUM_LOCKto lock num.
I tested this on windows. I'm not sure about other OSs, but I think it will work.
source
share