How do I turn the Num Lock button on?

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);


Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me by donating.

Leave a Reply