JavaFX KeyEvent returns KeyCode.UNDEFINED

后端 未结 1 687
离开以前
离开以前 2021-01-18 05:58

I created a simple JavaFX application that receives input from the user in a TextField. I attached the KeyTyped event from SceneBuilder to the controller. My function looks

1条回答
  •  悲哀的现实
    2021-01-18 06:10

    KeyTyped is a special event. It doesn't have KeyCode but has character set instead.

    See example for letter 'a':

    KeyEvent [source = TextField[id=null, styleClass=text-input text-field], 
    target = TextField[id=null, styleClass=text-input text-field], eventType = KEY_TYPED, consumed = false, 
    character = a, text = , code = UNDEFINED]
    

    and javadoc: http://docs.oracle.com/javafx/2/api/javafx/scene/input/KeyEvent.html#getCode()

    The key code associated with the key in this key pressed or key released event. For key typed events, code is always KeyCode.UNDEFINED.

    0 讨论(0)
提交回复
热议问题