How to know when a user has really released a key in Java?

前端 未结 10 1341
孤城傲影
孤城傲影 2020-11-30 11:09

(Edited for clarity)

I want to detect when a user presses and releases a key in Java Swing, ignoring the keyboard auto repeat feature. I also would like a pure Java

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 11:54

    Save the timestamp of the event (arg0.when()) in keyReleased. If the next keyPressed event is for the same key and has the same timestamp, it is an autorepeat.

    If you hold down multiple keys, X11 only autorepeats the last key pressed. So, if you hold down 'a' and 'd' you'll see something like:

    a down
    a up
    a down
    d down
    d up
    d down
    d up
    a up
    

提交回复
热议问题