java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to turn the Caps Lock button on?

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

package com.javacoderanch.example.awt;

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

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

        // Update the locking state for caps lock button to true 
        // will turn the caps lock on.
        toolkit.setLockingKeyState(KeyEvent.VK_CAPS_LOCK, Boolean.TRUE);