_kbhit() function

I got this code from goti.

1
2
3
4
5
6
7
8
9
char getinput()
{
    if (_kbhit())
    {
        _getch(); // edit : if you want to check the arrow-keys you must call  getch twice because special-keys have two values
        return _getch();
    }
    return 0; // if no key is pressed
}


Could anyone explain the comment of goti in _getch()? I don't know how to implement "call getch twice"

1
2
3
4
5
6
    if (_kbhit())
    {
        _getch();
        _getch(); //is this what he mean to call getch twice?
        return _getch();//how about this?
    }

My problem is I want to check if the user pressed the arrow keys.

Thanks.
have you tested? try a sample program if yours is not compiling as of yet.
Last edited on
Topic archived. No new replies allowed.