FileDocCategorySizeDatePackage
KeyboardFlasher.javaAPI DocExample1227Mon Jan 09 11:02:00 GMT 2006None

KeyboardFlasher

public class KeyboardFlasher extends Object implements AWTEventListener

Fields Summary
Constructors Summary
Methods Summary
public voideventDispatched(java.awt.AWTEvent evt)

        if(evt instanceof KeyEvent) {
            KeyEvent kevt = (KeyEvent)evt;
            if(kevt.getID() == KeyEvent.KEY_PRESSED) {
                System.out.println("key event: " + evt);
                if(kevt.getKeyCode() != KeyEvent.VK_SCROLL_LOCK) {
                    flipScrollLock();
                }
            }
        }
    
public voidflipScrollLock()

        Toolkit tk = Toolkit.getDefaultToolkit();
        boolean state = tk.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
        tk.setLockingKeyState(KeyEvent.VK_SCROLL_LOCK,!state);
    
public static voidmain(java.lang.String[] args)

        Toolkit tk = Toolkit.getDefaultToolkit();
        KeyboardFlasher flasher = new KeyboardFlasher();
        tk.addAWTEventListener(flasher, AWTEvent.KEY_EVENT_MASK);
        
        JFrame frame = new JFrame("Hack #63: Keyboard Flasher");
        JTextField tf = new JTextField("this is some text");
        frame.getContentPane().add(tf);
        frame.pack();
        frame.setVisible(true);