junkyboy
asked on
Ascii Code for Enter and Arrow
Can somebody tell me what the ascii code is for the ENTER key and the ARROW keys on the keyboard? I am using VisC++ 6.0 on NT4. I need to move a cursor on screen around, and I need to read arrow key inputs from the user. Thnx!
ASKER
This is what I have, and the [ENTER] key works, but the arrows don't. Can you tell me what the problem is in here:
void movecursor(int * ox, int * oy)
{
int x=*ox, y=*oy, fx=0, fy=0, escape=0;
char set;
textattr(26);
do{
gotoxy(x,y);
cout << "[" << endl;
gotoxy(x+2,y);
cout << "]" << endl;
set=getch();
gotoxy(x,y);
cout << " " << endl;
gotoxy(x+2,y);
cout << " " << endl;
switch(set)
{
case (25): fy=y; fx=x; y+=2; break;
case (24): fy=y; fx=x; y-=2; break;
case (27): fy=y; fx=x; x-=4; break;
case (26): fy=y; fx=x; x+=4; break;
case (13) : escape=1; break;
default : break;
}
if ((x<2) || (x>38))
x=fx;
if ((y<3) || (y>21))
y=fy;
if ((((x>=10) && (x<=17)) || ((x>25) && (x<32))) && ((y>=10) && (y<=14)))
{
x=fx;
y=fy;
}
}while(!escape);
textattr(28);
gotoxy(x,y);
cout << "[" << endl;
gotoxy(x+2,y);
cout << "]" << endl;
textattr(31);
*ox=x;
*oy=y;
}
void movecursor(int * ox, int * oy)
{
int x=*ox, y=*oy, fx=0, fy=0, escape=0;
char set;
textattr(26);
do{
gotoxy(x,y);
cout << "[" << endl;
gotoxy(x+2,y);
cout << "]" << endl;
set=getch();
gotoxy(x,y);
cout << " " << endl;
gotoxy(x+2,y);
cout << " " << endl;
switch(set)
{
case (25): fy=y; fx=x; y+=2; break;
case (24): fy=y; fx=x; y-=2; break;
case (27): fy=y; fx=x; x-=4; break;
case (26): fy=y; fx=x; x+=4; break;
case (13) : escape=1; break;
default : break;
}
if ((x<2) || (x>38))
x=fx;
if ((y<3) || (y>21))
y=fy;
if ((((x>=10) && (x<=17)) || ((x>25) && (x<32))) && ((y>=10) && (y<=14)))
{
x=fx;
y=fy;
}
}while(!escape);
textattr(28);
gotoxy(x,y);
cout << "[" << endl;
gotoxy(x+2,y);
cout << "]" << endl;
textattr(31);
*ox=x;
*oy=y;
}
Hi junkyboy,
Do you use Microsoft Visual C++ 6.0? And how are you able to use such DOS-specific function like gotoxy() and textattr()?
Do you use Microsoft Visual C++ 6.0? And how are you able to use such DOS-specific function like gotoxy() and textattr()?
ASKER
I'm creating a "Win32 Console Application" project using MS VisC++ 6.0, and I was able to use those functions by creating a customized version of those functions (got them from a previous answer by neitod).
It's your code... Why don't you put a breakpoint after your getch(), and just see what is it that your recieve when you press the arrow keys?
ASKER
Thnx, but I already got the codes off a book.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've already got the code, as I mentioned above. But, thanx anyways :)
up= 24
down= 25
right= 26
left= 27
enter is the same as (CR) which is ascii code 13