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?
NOVICE3

Recommended Answers

All 4 Replies

Since you didn't provide what the method _kbhit() does how could anyone answer you?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.