Solved

Ascii Code for Enter and Arrow

Posted on 2000-03-29
8
1,155 Views
Last Modified: 2008-02-20
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!
0
Comment
Question by:junkyboy
8 Comments
 

Expert Comment

by:BCheatham
ID: 2667770
ascii code for arrow
up=    24
down=  25
right= 26
left=  27

enter is the same as (CR) which is ascii code 13
0
 

Author Comment

by:junkyboy
ID: 2668306
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;
}
0
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2668388
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()?
0
 

Author Comment

by:junkyboy
ID: 2669263
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).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:yarond
ID: 2679374
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?
0
 

Author Comment

by:junkyboy
ID: 2684066
Thnx, but I already got the codes off a book.
0
 

Accepted Solution

by:
kishore_joshi earned 40 total points
ID: 2689430
Hai,
The ascii code for enter key is 13.

And for the arrow keys u need to use the scan-code .

KEYS                  SCAN CODE    

up arrow key          72
down arrow key     80
left arrow key         75
right arrow key       77

home key               71
end    key               79
ins     key                82
del    key                83


0
 

Author Comment

by:junkyboy
ID: 2690035
I've already got the code, as I mentioned above.  But, thanx anyways :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 134
c++ how to tell if the progra is ctl or mfc atl ect 6 64
C++ Class Serialization, Encapsulation and Formatted Output 8 54
computer science syllabus 3 70
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now