0

Hi all,

I have searched about difference between KeyPressed and KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped .

Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ?

Thanks in advance

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by javaAddict
0

I think that KeyPressed is triggered exactly when you press the key. Meaning that you don't have to release the key (lift you finger from the key) to be activated.
As for the KeyTyped I think that is activated you release the key, although I am not sure.

You can test this by adding a System.out.println() inside the "triggers" and when you press the key, keep it pressed and check the console what has printed. Then lifted it and check again.

If someone else knows more please correct me.

I know that the mouse events work the way I described because I used the "mousereleased" (if i remember the name correctly) as trigger for a tic-tac-toe game I made. The 'X' was displayed at the GUI when I was releasing the mouse key

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.