View Single Post
  #56   Spotlight this post!  
Unread 08-06-2002, 00:13
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I think I've got the solution...

Going back to a previous post (by gwross), your best method will be to use kbdhit(). It will return 0 if no key has been pressed, and 1 if a key has been pressed. Since I assume you only want it to quit when a certain key is pressed, you can then issue a getch() which will return the key that was pressed. Just compare it, and you should be good to go. Just make sure to include <conio.h>.
Here's the code I tested it with:
while(true){
if(kbdhit()){
cout<<"key pressed:";
myChar=getch();
cout<<myChar<<"\n";
if(myChar=='q')
return 0;
}
else{
cout<<"no key pressed\n";
}
cout.sync_with_stdio()
}

BTW, that cout.sync_with_stdio() is because I was having problems with the output being very sluggish.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php