Problems with kbhit().

Hello.
I am making a game where it detects if a key is pressed or not, and i am using kbhit(). But once a key is pressed, kbhit always returns 1, even if there is no key pressed. What am I doing wrong? Thanks.


#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int main()
{
    int i;
    while(true)
    {
        i=kbhit();
        if(i==1)
        {
            cout<<"You pressed a key.";
        }
        Sleep(0.5*1000);
    }

 return 0;
}

You need to read the key. kbhit just tells you if there's a value to be read.
It works fine now. Thanks
Topic archived. No new replies allowed.