0

Say I have an event in a particular time interval that requires the user to pressed the SPACE key as many times as they can in 10 seconds. How, would I write something like that with/without creating a GUI for it? Right now, I am working purely within the Eclipse console.

3 Answers3

1

You cannot detect key presses (except for return) in the Eclipse console.

See this answer: https://stackoverflow.com/a/9545470/6697722

Basically, you need to use something such as JCurses

Community
  • 1
  • 1
learner0000
  • 293
  • 2
  • 11
0

I assume within the Eclipse console you could do it as follows:

Give the user a new, empty line to type in when the time starts. Let the user now do the key-presses. After your time's up. You can read the input in that line and count the amount of spaces.

This should give you the amount of times the space bar has been pressed.

Jeanma
  • 61
  • 6
0

A good starting point would be to look at this answer:

How do I check if the user is pressing a key?

In Java, you don't check if a key is pressed however you need to listen with the appropriate listener.

Community
  • 1
  • 1
Adam
  • 1
  • 1