Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I want to write a program which detects when a specific key(say Spacebar) is pressed and it increments an integer variable and displays the output as incrementing milliseconds starting from 0 and when i release the key it can decrement in the same rate to 0.

Even a suggestion on how to try this thing will be a help. I'll try on my own but currently i am unable to figure out this thing.

Thanks in advance !!

What I have tried:

I am currently working on core java libraries and trying to create simple programs. I am unable to do this using the class Scanner. I think it is not possible to do this using the Scanner class.
Posted
Updated 27-Sep-16 22:09pm
v2

1 solution

No it is not able to do this with the Scanner class. You would need a method that gets activated when a key is pressed, and also when it is released. See https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html[^].
 
Share this answer
 
Comments
CPallini 28-Sep-16 4:24am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900