Ascci program...

do
{
c = getch();
cout << c << endl;
}
while (c != 27);


When I input an arrow key two ascci codes are displayed... namely 224 and another number.........how is that.....
Keyboards work by generating "make codes" when keys are pressed and "break codes" when keys are released. These are collectively called scan codes. Scan codes are independent of ASCII.
Some keys generate more than one scan code. Each scan code is translated into an ASCII code.
Many of the "special" keys -- like home, end, pg up, pg dn, etc generate more than one make code.

Google "keyboard scan code" for more details.
that is very interesting, I must say I had no idea. but how would you know be able to use the '224' and '75' to determine which key the user pressed?

I tried some things like:

c = getch();
if (( c == 224) && (c == 75))
cout << "left arrow" << endl;

even

#include <complex>
complex<int> real;
real = c = getch();
if (real == (224,75))
cout << "left arrow" << endl;



but nothing works.
what would one do?







Last edited on
You have to read two characters.

1
2
3
4
5
6
7
8
char ch1 = getch();
if( ch1 == 224 )
{
    char ch2 = getch();
    if( ch2 == 75 )
        cout << "left arrow\n";
    else if( ch2 == ... )
}

Are you trying to say that the scan codes are buffered in the input buffer..........and getch() accepts these from the buffer.........


I
yes.
thanks...
Topic archived. No new replies allowed.