_getch(): RETURN Values...

So, I have decided to experiment with _getch... Interestingly enough, I have found that there are different 'escape' values returned for different kinds of control keys...

For example:

-32 was returned for both the END and the Delete keys, and the following numbers represented their actual scan codes.

for F1 and F2, 0 was returned, and following, their scan codes.

This leads me to a particular question: Are these codes the same for every keyboard? I have doubts that they are...

I read up, and found a very nice post by duos. In his mini-article, he says that for control characters, 0 is returned to signify that a control character was pressed, and then the scan code is sent. Unfortunately, I saw nothing in there about there being different escape codes for different control keys. Furthermore, I find myself wondering if it could be OS-dependent...

Note: I did cast the codes as an integer (psudo code): char ch; cout<< int(ch);

so, to sum it up:

Are the escape/scan codes unique for each piece of hardware, or are they standardized?

Are the escape/scan codes OS-dependent?
The leading underscore on the name is the hint. It's platform/environment specific.

Scan codes are specific to a keyboard. Ad keyboard driver converts these to characters (in a character set).

Escape codes are standardised (see ANSI.sys). Scan codes are hardware specific, but there seems to be defacto standards, which would explain why you only need a keyboard driver for so special/unusual keyboard.
Ah. Thank you.

I will experiment with getch() instead of _getch() then.
I did some experiments: getch() returns the same values as _getch().

I am reading up about ansi.sys now...

EDIT: my research on ANSI.sys was very enlightening... but I did not find much on escape codes...
Last edited on
Topic archived. No new replies allowed.