Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

keyboard values

keyboard values

keyboard values

I am writing a program that uses the arrow keys on the keyboard. can somebody tell me the best way to go about this or tell me the values for these keys.


RE: keyboard values

Here is a list I have. It is a bit old but I don't think it has changed. Assuming that:

int c;

Then if c = getch(); and the user presses an arrow key, c should return
72 = Arrow up
75 = Arrow left
77 = Arrow right
80 = Arrow down

If you want to see what other keys return, try this:

#include <conio.h>
#include <iostream.h>

int main()
    char c, k; // characters for key presses

   while (1)
        // loop forever
        c = getch(); // get a key press
        if (!c)
             // Some keys generate two bytes, the first is a NULL
             k = getch(); //  So we need to get more
             cout << c << ", " << k << endl; // Show what we have, including NULL
             // Otherwise we can just print the key code
             cout << c << endl;
     if (c=='q') break; // Lets get out of here

This is some code I picked up off a newgroup several years ago. I haven't tested it on some of the newer compilers so beware.

James P. Cottingham

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close