Exemple #1
0
 /**
  * Wait until any key is pressed within the time indicated This method also checks action keys
  * (Cursor arrows, Home, etc.).
  *
  * @param timeout Maximum time to wait in milliseconds. If is 0 wait forever
  * @return The key pressed or a negative value if no key was pressed (NO_KEY or MOUSE_CLICK).
  * @see #getKeyPressedUntil(long)
  * @see #getKeyPressed()
  * @see #getMouseEvent()
  */
 public static int waitKeyPressed(long timeout) {
   if (timeout < 0) timeout = 0;
   if (timeout > 0) timeout += System.currentTimeMillis();
   int k;
   while ((k = frame.getKeyPressed()) == NO_KEY
       && (timeout <= 0 || System.currentTimeMillis() < timeout)) ;
   return k;
 }
Exemple #2
0
 /**
  * Returns the code of a key that is pressed, probably the last pressed. It may be more than one
  * key pressed at the same time. This method also checks action keys (Cursor arrows, Home, etc.).
  *
  * @return The code of the key pressed or a negative value if no key was pressed.
  *     <p>- NO_KEY (-1) if no key was pressed
  *     <p>- If <code>mouseClick(true)</code> and there was a mouse click and no key was pressed
  *     return MOUSE_CLICK (-2)
  * @see #isKeyPressed(int)
  * @see #waitKeyPressed(long)
  * @see #enableMouseEvents(boolean))
  * @see #getMouseEvent()
  */
 public static int getKeyPressed() {
   return frame.getKeyPressed();
 }