key reading

i would like it to read if any key is being pressed for the time its pressed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int main()
{
	bool pressed = true;
	while (true)
	{
	if (pressed)//any button pressed
	{
		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'm a bit confused on the iostream and std then you use printf. :P anyways it will vary based on what operating system you are on. Windows you can use http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx otherwise you'd have to find the equivalent in another os.
Topic archived. No new replies allowed.