In a C# Console app, pressing the Pause key freezes the display output. Can I disable that?
I was hoping for a handler like the Console.CancelKeyPress event that handles Ctrl+C input.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every once in a while a request comes up for hooking keys from a console program. The standard events like
CTRL_C_EVENTandCTRL_CLOSE_EVENTdo not include the Pause-event. I’ve tried doing so using a background thread, but I don’t seem to manage. However, there’s a not-so-hard workaround: use an extra process.Download this easy-to-use global keyboard hook for C#. Then, when you open that project, take the following code and put it in the Form1.cs:
Then, the rest becomes trivial:
I tried the above myself and it works.
PS: I don’t mean that there isn’t a possible way straight from a Console program. There may very well be, I just didn’t find it, and the above global keyhook library didn’t work from within a Console application.