423,818 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,818 IT Pros & Developers. It's quick & easy.

How to avoid pressing enter while taking the input?

P: 27
I am working on a kind of typing practice application.
There will be some text on the screen. What I want to do is just remove the characters (starting from the beginning) if the user presses the right one.

For example:
(output screen)

This is some sample text

Error count: 0

*when the user presses 'T'*

his is some sample text

Error count: 0

*when the user presses 'h'*

is is some sample text

Error count: 0

*if the user presses the wrong one, it adds up in the error count*

like, *if the user presses 'm'*

is is some sample text

Error count: 1

---------------------------------
Currently the code removes the correctly typed characters from the output text. Maybe changing their color would be even better.

Using this way, the user has to press 'Enter' after the input of a character every time. So, the question is how can the input be extracted from the buffer without pressing enter? Like whenever the user presses any character, the code can automatically take action and update the screen accordingly. Can this be done using event/key listeners or is there any other method?
Jun 5 '18 #1

✓ answered by weaknessforcats

When you ask for input, your program stops. The input starts up and continues until there is no more input. Then the input stops and your program starts. The system needs to know when the input stops and this is usually the enter key.

This is the default C++ behavior. Professional developers often write their own input driver to get around this stop/start situation. You won't do that as a beginner.

My suggestion is to make this easy on yourself. Have the use provide the input, then pres enter, then you can process the input buffer.

Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,196
When you ask for input, your program stops. The input starts up and continues until there is no more input. Then the input stops and your program starts. The system needs to know when the input stops and this is usually the enter key.

This is the default C++ behavior. Professional developers often write their own input driver to get around this stop/start situation. You won't do that as a beginner.

My suggestion is to make this easy on yourself. Have the use provide the input, then pres enter, then you can process the input buffer.
Jun 5 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.