Ascii code for direction keys

This is a discussion on Ascii code for direction keys within the C++ Programming forums, part of the General Programming Boards category; Would anyone happen to know the ascii code in octal for the up, down, left and right keys?...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    20

    Ascii code for direction keys

    Would anyone happen to know the ascii code in octal for the up, down, left and right keys?

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    They don't have single byte ASCII references as far as I remember.

    but you can use this:

    Code:
    #include <stdio.h> 
    #include <limits.h> 
    #include <stdlib.h> 
    #include <windows.h> 
    
    int main ( void )
    {
      short esc = 0;
    
      while ( !esc ) {
        esc = GetAsyncKeyState ( VK_ESCAPE );
    
        if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX )
          puts ( "Up arrow is pressed" );
        else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX )
          puts ( "Down arrow is pressed" );
        else if ( GetAsyncKeyState ( VK_LEFT ) & SHRT_MAX )
          puts ( "Left arrow is pressed" );
        else if ( GetAsyncKeyState ( VK_RIGHT ) & SHRT_MAX )
          puts ( "Right arrow is pressed" );
      }
    
      return EXIT_SUCCESS;
    }
    came from here

    That way you don't have to remember them

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    20
    ok, Thx man

    would there be anyway to find out its code in a program?
    like
    Code:
    char a = getch();
    string thing=((oct)a);
    cout<<thing;
    and maby converting back to ascii?
    Last edited by Whizza; 05-24-2006 at 04:17 AM.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Here is a short program that will tell you the value of the keys. When you run it press all the keys you want to find out their ascii values. Special keys return the same value as other ascii keys, so I make special keys negative to distinguish the difference. Other programmers sometimes add 255 instead of making them negative.
    Code:
    #include <conio.h>
    #include <iostream>
    using namespace std;
    
    #define ESC 27
    int main()
    {
    	int c = 0;
    	while( c != ESC)
    	{
    		c = getch();
    		if(c == 0 || c == 224)
    			c = -getch();
    		cout << c << endl;
    
    	}
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 02:29 PM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  4. covert ascii code to character
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 10:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21