How to check if Scroll Lock is on or off?
How does one check to see if Scroll Lock is enabled on开发者_如何学编程 a system or not in Java?
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
Source: http://www.kodejava.org/examples/574.html
use getLockingKeyState() method from toolkit
Toolkit toolkit=Toolkit.getDefaultToolkit();
toolkit.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
You can also set them ON / OFF by
toolkit.setLockingKeyState(KeyEvent.VK_SCROLL_LOCK,true);
精彩评论