How do I read the up, down, left, and right arrow keys as a
character?
Using getch(), they all seem to have the ascii value of zero, and I can't distinguish them individually.
Thanks.
Printable View
How do I read the up, down, left, and right arrow keys as a
character?
Using getch(), they all seem to have the ascii value of zero, and I can't distinguish them individually.
Thanks.
try this:
find out what the numbers for the arrow keys are, then doCode:int testnum = getch();
printf("%d",testnum);
Code:int input;
input = getch();
switch(input)
{
case 14: left(); break; // depends on what numbers you get from the arrow keys in the test code if it's 40, then do case 40:.
...etc...
It doesn't work. The arrow keys don't have individual ascii values. They are all null. Even more annoying is the fact that they stay resident in stdin.
Not with my compiler...
The arrow keys are NOT null. They are actually two keystrokes. One is an escape or control sequence, the second is the actual response.
Quzah.
#include <stdio.h>
int main() {
int num;
clrscr();
num = getch();
if (num) printf("%d", num);
else puts("NULL");
return 0;
}
run this is a *.c file
type in any arrow key, you will get "NULL"
I know in Turbo Pascal 7, there is a demo program called Breakout that uses arrow keys. Since borland makes it, the I/O
might be similar. I might have to check it out.