Friday, March 8, 2013

Java : ON OFF capsLock, Numlock and scrollLock

 Java : ON OFF capsLock, Numlock and scrollLock


public boolean capsLock(boolean cp) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        tk.setLockingKeyState(KeyEvent.VK_CAPS_LOCK, cp);
        return true;
    }
    public boolean numLock(boolean np) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        tk.setLockingKeyState(KeyEvent.VK_NUM_LOCK, np);
        return true;
    }
    public boolean scrollLock(boolean sp) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        tk.setLockingKeyState(KeyEvent.VK_SCROLL_LOCK, sp);
        return true;
    }

    public boolean onAllKeys() {
        return capsLock(true) & numLock(true) & scrollLock(true);
    }
    //This method off all three buttons
    public boolean offAllKeys() {
        return capsLock(false) & numLock(false) & scrollLock(false);
    }