Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivalent to BASIC "INKEY$ In C and/or C++

Status
Not open for further replies.

kaplana

Programmer
Jun 28, 2000
6
US
I have created a game in BASIC in which I can input data numerous times represented by key strokes while the program is running using "If INKEY$=CHR$()". I am trying to translate this game into C and/or C++, but cannot find an equivalent command. It appears that I can use (kbhit()) once while the program is running, but not more often. Is there a way that I can impliment the above BASIC command in C and/or C++?
 
Yes you can use kbhit(). put

while(1)
{
if(kbhit())
{
c = getch();
if(c == 0) c = getch();
else if(c == 27) break;
}
}

this loop will wait upto a Esc keystoke from the user.

Regards
Maniraja S









 
How about to set an interruption? is much faster then kbhit...getch... John Fill
1c.bmp


ivfmd@mail.md
 
you can write some code like this:

int inkey()
{
int keypress = 0 ;
fflush(stdin) ;
while (!keypress) keypress = getch() ;
return(keypress) ;
}

this works like your inkey

hope this helps

Subra if you find this useful let me know at vksubra@usa.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top