1

I want to determine the current state of CapsLock using Java. I have tried the following so far.

  1. Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK) always returns true
  2. I cannot use key listeners as they will inform about CapsLock key being pressed or released but what I want is to detect whether CapsLock is on/off.

Is there any other possible way to check the state of CapsLock key in Java?

howlger
  • 31,050
  • 11
  • 59
  • 99
safaarooj
  • 11
  • 5
  • Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); works for me – Akceptor Dec 31 '18 at 11:06
  • 3
    Possible duplicate of [How can I get the Caps Lock state, and set it to on, if it isn't already?](https://stackoverflow.com/questions/7435221/how-can-i-get-the-caps-lock-state-and-set-it-to-on-if-it-isnt-already) – kasptom Dec 31 '18 at 11:06
  • try KeyboardUtils from checking link below: https://stackoverflow.com/questions/12020835/how-do-i-check-if-the-caps-lock-key-is-pressed – Amir Hedieh Dec 31 '18 at 11:45

1 Answers1

-1

getLockingKeyState(KeyEvent.VK_CAPS_LOCK)

Read more at https://docs.oracle.com/javase/6/docs/api/java/awt/Toolkit.html#getLockingKeyState%28int%29

Vegas
  • 8,017
  • 1
  • 10
  • 14