×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

ASCII code for arrows

ASCII code for arrows

ASCII code for arrows

(OP)
I would like to know ASCII codes for keyboard arrows.Any information welcomed.

RE: ASCII code for arrows

milosd,

I think this is what you are looking for. You have to remember that "special" keys like the arrow keys require special handling since they generate two bytes instead of one. The first byte is NULL. For the second byte, the down arrow key produces "80", the up arrow produces "72", the left arrow produces "75", and the right arrow produces "77."

If you are interested, I have a snippet of code that will show you the ascii code for those special keys. It is a piece of code I picked up off a borland newsgroup. I haven't tested it so I can't say if really works or not.


James P. Cottingham
main@ivcusa.com
International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

RE: ASCII code for arrows

As 2ffat says, you have to read the key twice for an extended code. Here's how in the DOS environment (Windows is different) :

a = getch(); /* Get key press */
if (a == 0 ¦¦ a == 0xE0) { a = getch() + 0x100; } /* Add 256 if extended: This makes the rest of the code easier to write */
switch ( a )
{
case 27: /* If escape key */
printf( "Exiting..." );
goto end; /* Sorry ;) */
case 328: /* If Up Arrow key */
/* Do stuff for Up Arrow Key */
break;
case 336: /* If Down Arrow key */
/* Do stuff for Down Arrow Key */
break;

The rest of the keycodes can be figured out by putting this into the above code before the switch(a) statement:

printf("Keycode is %d\n", a );

I hope this helps.


Kim_Christensen@telus.net
Home Page

RE: ASCII code for arrows

Here is the snippet of code that I found that shows what the ascii codes are for keys presses. It's DOS based and I can't say how well it works since I've never compiled it.

#include <conio.h>
#include <stdio.h>

int main()
{
int a, b;
while (1)
{
a = getch();
if (!a)
{
b = getch();
printf("%3i, %3i \n", a, b);
}
else printf("%3i \n", a);
if (a == 'q') break;
}
return 0;
}

No telling where the original code came from or how many changes have been made in the mean time. I suppose that I should test the code before I post it but . . .

zBuilder's code is more practical but this code should show you the ascii code of keys.

Good Luck!

James P. Cottingham
main@ivcusa.com
International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

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