key pressed

i have no idea about hte part where it says "if GetAsyncKeyState(vkey)" this is what some guy gave me i need it to be able to read if any key is being pressed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
	int key;

	while (true)
	{
		if GetAsyncKeyState(vkey)
		{
			printf("button has been pressed \n");// if a key is being held down
		}
		else
		{
			printf("button is not pressed \n");// if no button is held down
		}
	}
}
i have windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <conio.h>
#include <windows.h>
#define _VK_P 0x50
void _clrscr()
{
    COORD Home={0,0};
    DWORD Written;
    HANDLE conOut=GetStdHandle(STD_OUTPUT_HANDLE);
    FillConsoleOutputCharacter(conOut, //The specified HANDLE , in this case Output Handle
                               (TCHAR)' ', //Fill The screen buffer with spaces(or other character)
                               10, //How many spaces(or other character) to fill with
                               Home, //Start filling with spaces from coordinates 0,0
                               &Written); //The Written variable shows the characters(spaces in this case) actually written
    SetConsoleCursorPosition(conOut,Home); //Set cursor position back to 0,0
}
int main()
{
    int key;
    _cputs("Press \'P\'");
    while(true)
    {
        if(GetAsyncKeyState(_VK_P))
            break;
    }
    _clrscr();
    _cputs("Congrats you passed the test\n\n");
    _cputs("Oh and the other key you presed are : ");
    while(kbhit()) _getche(),putch(',');
   // _cputs("\b\b\b.  ");
    _getch();
    return 0;
}
Topic archived. No new replies allowed.