Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import java.awt.*;
import java.awt.event.*;
/**
* This class is an example of one method for checking the
* state of the CAPS and NUM lock keys before a KeyEvent has
* been generated. On some platforms, the
* Toolkit.getLockingKeyState() method is not supported and
* throws an UnsupportedOperationException. The hack
* creates a new java.awt.Frame, generates some appropriate
* KeyEvents using java.awt.Robot to be received by an
* anonymous inner class. After the hack does it's job, the
* Frame is disposed to release the memory.
*/
public class capstest {
public static void main( String [] args ) {
Frame frame = new Frame( "Checking Locking Key State ..." );
frame.addKeyListener( new KeyAdapter() {
public void keyPressed( KeyEvent e ) {
if ( Character.isLetter(e.getKeyChar()) ) {
if ( Character.isUpperCase(e.getKeyChar()) )
System.out.println( "CAPS Lock is On" );
} else {
if ( Character.isDigit(e.getKeyChar()) )
System.out.println( "NUM Lock is on" );
}
}
});
// If the frame isn't set visible, the key presses
// go to the console rather than to the frame
frame.setVisible( true );
try {
Robot robot = new Robot();
robot.keyPress( KeyEvent.VK_A );
robot.keyRelease( KeyEvent.VK_A );
robot.keyPress( KeyEvent.VK_NUMPAD5 );
robot.keyRelease( KeyEvent.VK_NUMPAD5 );
frame.dispose();
} catch ( AWTException e ) {
}
}
}