How can I detect if caps lock is toggled in Swing?

后端 未结 3 798
臣服心动
臣服心动 2020-12-09 17:42

I\'m trying to build a better username/password field for my workplace and would like to be able to complain when they have their caps lock on.

Is this possible? An

相关标签:
3条回答
  • 2020-12-09 17:46

    here is some info on the class http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getLockingKeyState(int)

    0 讨论(0)
  • 2020-12-09 18:01

    In addition to Nick's answer, to react to this condition before the user presses a key, you can listen to the focus event of your text entry component and test the caps-lock as the component receives focus.

    0 讨论(0)
  • 2020-12-09 18:02

    Try this, from java.awt.Toolkit, returns a boolean:

    Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)
    
    0 讨论(0)
提交回复
热议问题