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

KeyEvent.code does not contain a useful value in onKeyTyped events

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      OS X, 10.5.5 JAva 1.6.0_7

      Description

      When trying to detect backspace keystrokes by using the onKeyXXX events on a group I find that the code value does not get populated with a useful value in onKeyTyped events.

      This means that detecting the keystrokes of a delete key being held down can't be done unless the programmer also provides and onKeyPressed handler and copies the KeyCode to their own variable for use in the onKeyTyped handler.

      Not sure if this is intended behavior.

      E.g

       onKeyPressed: function (e: KeyEvent):Void {
                      myCode = e.code;
                  }
                  onKeyTyped: function( e: KeyEvent ):Void {

                      if (myCode == KeyCode.VK_BACK_SPACE) {
                          if (this.text.length() > 0) {
                              this.text = this.text.substring(0, text.length() - 1)
                          }
                          
                      } else {
                          text += e.char;
                      }

                      if (textControl.layoutBounds.width > clipSize)
                      {
                          if (myCode == KeyCode.VK_BACK_SPACE) {
                              textControl.translateX += 5;
                          } else {
                              textControl.translateX -= 5;
                          }
                      }
                      println(this.text.length());
                      cursorPosition = textControl.layoutBounds.width
                  }
                 
                  }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kcr Kevin Rushforth
                Reporter:
                sherodjfx Steven Herod (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: