質問

I have a program like this:

#include <iostream>
#include <conio.h>
using namespace std;

int main ()
{
    for (int i = 0; i < 10; i++)
    {
        cout << int (_getch ()) << endl;
    }
    _getch ();
    return 0;
}

If I press keys like digits, alphabets and Enter, a single integer is displayed (per iteration of the loop). However, if I press keys like Insert, Delete, or the arrows, two integers are displayed at once.

Why does this behaviour occur?

役に立ちましたか?

解決

From _getch()

When reading a function key or an arrow key, each function must be called twice;

The first call returns 0 (for F1-F10) or 0xE0 (224) (for others) , and the second call returns the actual key code.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top