How to avoid pressing enter while taking the input?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    How to avoid pressing enter while taking the input?

    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?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    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.

    Comment

    Working...