How do I turn the Num Lock button on?

Category: java.awt, viewed: 3K time(s).

The example below show you how to activate the num lock button programmatically. Setting the locking state to Boolean.TRUE will turn the num lock on.

package org.kodejava.example.awt;

import java.awt.Toolkit;
import java.awt.event.KeyEvent;

public class TurnNumLockOn {
    public static void main(String[] args) {
        //
        // Gets the default toolkit.
        //
        Toolkit toolkit = Toolkit.getDefaultToolkit();

        //
        // Update the locking state for num lock button to true
        // will turn the num lock on.
        //
        toolkit.setLockingKeyState(KeyEvent.VK_NUM_LOCK, Boolean.TRUE);
    }
}
Powered by Disqus