Looking for something to record a key press.

Alright so I know a lot of these functions. But I can't find the correct one for the purpose I want. I want to be able to record the key presses on my computer while the console window is not the active window. So for example I want something running in the background like:

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

int main()
{
	std::string pressed = "";
	bool running = true;

	while(running)
	{
		if(_kbhit())
		{
			char key = _getch();
			pressed.push_back(key);
			std::cout << pressed << std::endl;
		}
	}
	return 0;
}


Anyone know any functions that I can use to do this?
If it is windows - look into making a "keyboard hook".

I've never written one - but there is a load of info about.


If *nix - then I have no idea.
Awesome, found what I needed. Thanks ;)
Topic archived. No new replies allowed.