Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8101066

Add key classification to KeyEvent

XMLWordPrintable

      When listening for key pressed and key released events it is often useful to know what *kind* of key, the user released, e.g. was it an F-key (F1, F2, ...), an arrow key, or perhaps a modifier key (like Ctrl).
      Currently, if I want to know if the user released any kind of function key, I will have to write quite elaborate code like

      if(keyEvent.getCode() == KeyCode.F1 || keyEvent.getCode() == KeyCode.F2 || keyEvent.getCode() == KeyCode.F3 || ... ... ...)

      To avoid this, I am requesting the addition of a number of key classification methods, that would allow me to check if the user hit any kind of function key with a single method like this

      if(keyEvent.isFunctionKey())


      I think a natural set of methods could be

      KeyEvent.isFunctionKey() //F1, F2, F3, ..., F24
      KeyEvent.isArrowKey() //UP, DOWN, LEFT, RIGHT
      KeyEvent.isModifierKey() //Ctrl, Alt, Shift, Meta
      KeyEvent.isMediaKey() //VOLUME_UP, PLAY, PAUSE, REWIND, ...
      KeyEvent.isLetterKey() //A, B, C, ..., Z plus all other keys for which Character.isLetter returns true (to get national keys like Æ, Ø, Å as used in countries like Denmark, Sweden, Germany, etc.)
      KeyEvent.isDigitKey() //1, 2, 3, ..., 0 above the QWERTY keys as well as 0, 1, 2, ..., 9 on the numeric key pad
      KeyEvent.isQwertyDigitKey() //1, 2, 3, ..., 0 above the QWERTY keys
      KeyEvent.isKeypadDigitKey() //0, 1, 2, ..., 9 on the numeric key pad

        1. key.diff
          19 kB
          Martin Sládeček

            msladecek Martin Sládeček
            risaksen Randahl Isaksen
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: