Java examples on Java AWT
- How do I read image file?
- How do I create a beep sound?
- How do I create key press event using Robot class?
- How do I create mouse event using Robot class?
- How do I get the colour of a screen pixel?
- How do I create a screen capture using Robot class?
- How do I get my screen size?
- How do I get the location of mouse pointer?
- How do I get the available font names?
- How do I get screen's display mode information?
- How do I get the available font family names?
- How do I get number of available screens?
- How do I turn the Num Lock button on?
- How do I get mouse number of buttons?
- How do I turn the Caps Lock button on?
- How do I launch user-default mail client application?
- How do I turn the Scroll Lock button on?
- How do I read the status of Caps Lock key?
- How do I open a file using the default registered application?
- How do I read the status of Num Lock key?
- How do I read the status of Scroll Lock key?
- How do I print a file using the default registered application?
- How do I launch user-default web browser?
- How do I edit a file using the default registered application?
How do I read the status of Caps Lock key?
This example show you how to detect if the Caps Lock key is in active mode.
package org.kodejava.example.awt;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
public class CapsLockState {
public static void main(String[] args) {
//
// Get the locking state of the Caps Lock button. If it is "on" this method
// return boolean true value.
//
boolean isOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
System.out.println("CapsLock button is " + (isOn ? "on" : "off"));
}
}