title: How do I check if the caps lock key is pressed?
body: <p>Alright, before this gets flagged as a possible duplicate, I've already tried the following code:</p>
  
  <pre><code>Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)
  </code></pre>
  
  <p>And it is always returning false for me [see below]. Could someone confirm if this is supposed to be working, and I'm misusing it, or if it's known to be broken? If it is in fact broken, does anyone have a better method to use?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Alright, just found out something more. It appears to just return what it was at the begining of my programs launch. If I start the program with it on, it says its on, and vice versa. Here's my code:</p>
  
  <pre><code>while (true) {
      boolean isOn = Toolkit.getDefaultToolkit().getLockingKeyState(
          KeyEvent.VK_CAPS_LOCK);
      System.out.println("Caps lock is now: " + (isOn ? "ON" : "off"));
      try {
          Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
  }
  </code></pre>
  
  <p>And that's just always printing out whatever it started as</p>
  
  <p>(ex. if I start with caps lock on, even if I toggle it off right after, it prints:</p>
  
  <blockquote>
    <p>Caps lock is now: ON</p>
    
    <p>Caps lock is now: ON</p>
    
    <p>Caps lock is now: ON</p>
    
    <p>Caps lock is now: ON</p>
  </blockquote>
  
  <p>etc., if I start with it off, it will print off no matter what)</p>