Problem with GetKeyState();

I have a problem with this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int getkeys()
{
goback:
DWORD begtime=GetTickCount();
DWORD endtime=GetTickCount();
while(begtime+10>endtime) \\ Stops the program for 10 ms preventing stack overflow.
{endtime=GetTickCount();}
long up=GetKeyState(VK_UP);
if(up>0)
{return 1;}
long left=GetKeyState(VK_LEFT);
if(left>0)
{return 2;}
long down=GetKeyState(VK_DOWN);
if(down>0)
{return 3;}
long right=GetKeyState(VK_RIGHT);
if(right>0)
{return 4;}
goto goback; \\ If all other options fail(no key presses) it restarts the funtion.
}


It is meant to get the key currently down or stop the program until there is a key down, but if I call it again and there is no key down, it will give me the same key it did before. Please help me find a better way to do this. Thanks.
Last edited on
Topic archived. No new replies allowed.