For special keys, are there rules for the return value of getch? [duplicate]

  c++

I wrote this program to read keyboard operations:

#include <stdio.h>

#include <iostream>

#if defined _WIN32
#include <conio.h>
#else
#include <unistd.h>
#include <termios.h>
#endif

int getkeydown()
{
#if defined _WIN32
    return _getch();
#else
    struct termios oldt, newt;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    return ch;
#endif
}

int main()
{
    int ch;
    while (1)
    {
        ch = getkeydown();
        printf("[%X]", ch);
    }
    return 0;
}

For ordinary keys (such as characters) it works fine, but if you type keys like F1-F12, arrow keys, it will output multiple numbers at the same time.

Then I found link1 and link2.
I am not sure the documentation of xlib in link 2 is for which platform.

So, does getch have any relevant standards for these special keys, or what standards does different platforms have.

Can anyone provide some links, thank you.

Source: Windows Questions C++

LEAVE A COMMENT