This example show you how to detect if the Scroll Lock key is in active mode.
package org.kodejava.example.awt;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
public class ScrollLockState {
public static void main(String[] args) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
// Get the locking state of the Scroll Lock button. If it is "on"
// this method return boolean true value.
boolean isOn = toolkit.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
System.out.println("ScrollLock button is " + (isOn ? "on" : "off"));
}
}
If you run the program you will get an output telling you that the scroll lock button is active or not active.
Wayan Saryada
Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you 🥳
Latest posts by Wayan Saryada (see all)
- How do I set the time of java.util.Date instance to 00:00:00? - October 24, 2019
- How to Install Consolas Font in Mac OS X? - March 29, 2019
- How do I clear the current command line in terminal? - February 14, 2019