This example show you how to detect if the Scroll Lock key is in active mode. If you run the program you will get an output telling you that the Scroll Lock button is active or not active.
package org.kodejava.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. This method
// return boolean true value if it is "on".
boolean isOn = toolkit.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
System.out.println("ScrollLock button is " + (isOn ? "on" : "off"));
}
}
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023