Sorry for the lack of creativity when choosing my username, it was the first that worked...
On to what brought me here: My laptop's keyboard doesn't have the 3 Numlock, CapsLock and ScrollLock lights. After searching around for a program to do that, I decided to make my own. And I did:
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
public class NumCapScroll {
public static boolean isNumLockSet() {
return Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_NUM_LOCK);
}
public static boolean isCapsLockSet() {
return Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
}
public static boolean isScrollLockSet() {
return Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_SCROLL_LOCK);
}
}
And then I made a panel to show this info:
public class Panel1 extends JPanel {
private JCheckBox cbNum = new JCheckBox();
private JCheckBox cbCaps = new JCheckBox();
private JCheckBox cbScroll = new JCheckBox();
Timer t = new Timer(500, new ActionListener() {
public void actionPerformed(ActionEvent e) { refresh(); }
} );
private void init() {
// position everything
t.start();
}
public void refresh() {
cbNum.setSelected(NumCapScroll.isNumLockSet());
cbCaps.setSelected(NumCapScroll.isCapsLockSet());
cbScroll.setSelected(NumCapScroll.isScrollLockSet());
}
}
Everything works alright ( with some acceptable lag ) and I even found a way to create a system tray icon with this information, but I was wondering if there is a better way to do this. Like listening on system-wide keyboard events or something, because using a timer for this doesn't feel quite right.
Thanks in advance

New Topic/Question
Reply




MultiQuote



|