Detect Double Key Press In Java

As far as I know, there is no way in the Java API to detect a double keyboard press. While the mouse click events can detect a double or single click, there is no way with a KeyEvent class except to make one from scratch.

Here is a class I made to detect a double press on any key of the keyboard. If you notice, there is a variable called lastKeyPressedCode which records the last key pressed. With this class, you can easily detect a double key press on the same character by doing this in code:

Here is the KeyPressTool class.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *