Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
Hello, I would like to know the command to clear the keyboard buffer in C #.


What I have tried:

C#
I tried several commands but none worked, I do not know what to do.
Posted
Updated 3-Nov-16 9:43am
Comments
[no name] 3-Nov-16 9:58am    
Unless you tell us what you have already done and told us the problem we are likely just to tell you to try the same things. Google for the solutions that you haven't already tried and try them.

1 solution

For a console application:
C#
while (Console.KeyAvailable) 
{
    Console.ReadKey();
}


For a GUI application handle keyboard events and ignore them as required. See How Keyboard Input Works[^].
 
Share this answer
 
Comments
Member 12830814 3-Nov-16 16:25pm    
Not for console.
It is for windows forms
Jochen Arndt 3-Nov-16 16:35pm    
Well, you did not tell us what kind of application.
So I have answered for both types.

Because there is no single solution for GUI applications, I provided a link. Once you have read that and understand how keyboard input is working for Windows forms applications, you may refine your question (or recognise that discarding keyboard input from the user might be a bad idea).

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