I wanted to pause the execution of my program by requiring the input of a keystoke (any key). The idea was to put a message on a label something like "Change a switch to --- and then key any key to continue." I expected the program to wait until any key had been pushed using a statement like "while((ch = _kbhit()) != 0);". However, the program just goes right past the statement without stopping with ch = 0. What am I doing wrong?

5 Years
Discussion Span
Last Post by NOVICE3

The _kbhit() comes from the dll "crtdll.dll" which is present in windows/system32.


Since this is C#, unless you did a DLLImport (which you haven't mentioned at all) it isn't going to work. Did you mean to post in the C++ forum?

In C# you just put Console.Read();


I guess that I should be more general in asking for a solution to my problem. I am reading data from an array and performing differnt functions depending on the value extracted from the array, byte by byte. I have reserved the value of 01 for a special purpose of stopping the execution of the program, throwing up a message on a label to manually change the position of a switch and then hit any key to resume running the program. The program recognizes the 01 byte O.K., but then the trouble starts. If I use the line "Console.Read();", the message gets put up on the label O.K. but the program doesn't stop. Trying other methods do stop the program, but it won't start again when a key is pressed. The program frezes. I'm sure that experienced programmers do this sort of thing all the time, but for the life of me I can't figure out how.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.