473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to avoid pressing enter while taking the input?

dev7060
636 Expert 512MB
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.

1 1654
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

2
by: T.E. | last post by:
Hi all, I'm a newbie in php. I encounter a problem with php form that has only one textfield. If I click on the submit button, the form works fine. However, when I press 'enter', the form...
4
by: Jerry | last post by:
Hello I have some textboxes (input type=Text) in a Form. In some Forms if I Press Enter while I am in the Textbox It causes a Submit. The input type is text not submit. It's obsure that the...
2
by: Fernando Lopes | last post by:
Hi. I one usercontrol, i have a zipcode textbox . I need to, when user press ENTER, I call a code-behind method, to check this zipcode on database and, depending the return of this check,...
1
by: George Homorozeanu | last post by:
Hi, I have an ASP.Net Page with some control on it (buttons, textboxes, calender, etc). When I'm changing the text in the textbox I want to run some code and change the date of the calendar. The...
9
by: Camellia | last post by:
Hi all, I'll get straight into it. When I try to run the code: ..... while (scanf("%c", &c) == 1) printf("%c", c); ..... I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
1
by: Camellia | last post by:
Hi all, I'll get straight into it. When I try to run the code: ..... while (scanf("%c", &c) == 1) printf("%c", c); ..... I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
7
by: Monu2301 | last post by:
hello! I am new to java but as compared to any other language like c or c++ taking input in java is difficult but I tried using Keyborad.readInt(); for reading the inputs given by the...
1
by: ManishaGandhi | last post by:
Hello!!!!!!!!!!! I am beginner, can you please help me with the following problem? I have a form with 3 textboxes - txtBox1,txtBox2,txtBox3 on form load focus is on txtbox1 after i enter...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.