How do I read the status of Scroll Lock key?

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"));
    }
}
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.