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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting input without hitting Enter

Status
Not open for further replies.

ElWhapo

Programmer
Dec 1, 2004
2
0
0
US
I want to have the program utilize the left, right, up, and down arrows. My compiler doesn't like _getch(). Is there another way?

inkey = _getch(); // Use Something Other Than _getch(),
if(inkey==0x4B){ // Or Tell Me How To Use _getch().
.......
}
if(inkey==0x4D){
.......
}
 
If there's no reason you can't use Win32, you can use GetAsyncKeyState() to detect if specific keys are down, which could be combined with Sleep() and a loop to probably accomplish what you want. But what do you mean when you say your compiler doesn't like _getch()? If it can't find it, try getch() without the prefixing _, that works on an old Borland compiler I used in the past.

Also, it's a bad idea to use hex values directly in this case (inkey == 0x4B) because that's not at all clear to others what it is unless they have ascii memorized, and even then it could be simpler. You should either use the letter in quotes, or if its some special character, #define something that says what the character is instead of just putting the hex value.
 
I'd use a static const char instead of #define.
Especially in a big project where there could be other people defining the same thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top