I need to be able to have a function that I can use like kbhit() that I can get the char out of. No getch(), please. I'm not trying to pause the program. In fact, that's exactly what I want to avoid.
I need to be able to have a function that I can use like kbhit() that I can get the char out of. No getch(), please. I'm not trying to pause the program. In fact, that's exactly what I want to avoid.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
using getch with kbhit wont pause your program if you only call getch if kbhit returns true.
This won't pause your program because getch will read the key which ended the loop and move on to the other stuff.Code:while( ! kbhit() ) { // do stuff } ch = getch(); // do other stuff
All spelling mistakes, syntatical errors and stupid comments are intentional.
Smells good. Let me try it.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Try that, took it of msvc help.Code:#include <conio.h> #include <iostream> using namespace std; int main( void ) { char ch; // Display message until key is pressed. while( ! kbhit() ) cout << "Hit me!! "; // get the key pressed ch = getch(); cout << endl << "Key struck was " << ch; return 0; }
All spelling mistakes, syntatical errors and stupid comments are intentional.
Ok. Thanx.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
If you want to use kbhit() / getch() actively in a game loop:
Code:char Key=0; //Will loop until ESC is pressed while(Key!=27) { Key=0; if(kbhit()) Key=getch(); //Prints text when ENTER is pressed if(Key==13) cout << "You pressed Enter" << endl; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.