title: How do you get the current keyboard state globally? (i.e. what keys are currently depressed regardless of if the inquiring application has focus)
body: <p>I'm writing a screen capture utility, and I'd like to be able to store the current state of the keyboard and mouse whenever a screenshot is taken.</p>
  
  <p>Doing this for the mouse is simple, since using the <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation%28%29" rel="nofollow noreferrer">PointerInfo</a> class in a manner described in this <a href="https://stackoverflow.com/q/1439022/821806">related question</a> gives you the screen coordinates for the current mouse location and the click information if desired. However, I haven't been able to find an analog to this class for the keyboard; all the keyboard related classes appear to be focus specific.</p>
  
  <p>So, is there a way to get the current keyboard state in Java?</p>
  
  <p>P.S. Remember that I'm looking for a function to call to retrieve the information regarding what keys are depressed, <em>not</em> a listener for such depression events.</p>