program background captures keys

Is there a way to capture keys pressed, even when the C++ program is not the active form? I mean that the program is running but is in the background. So can a person be using Word and there still be a way to extract the keys they pressed from the buffer? I tried with kbhit() and getch() but I was not succesfull.
yes, with hooks.
ask on win32 api newsgroup :
news://comp.os.ms-windows.programmer.win32
(very classic question...)
thanks I used SetWindowshookEx() and I finally made it
Can you post your code on this here ?
Does anyone know of any tutorials or example scripts that use this function? Such as a keylogger or hotkeys.

Thanks,
Zach
as I said, tons of code have been posted on Usenet for ... nearly 20 years !
ask mainly on :
news://nntp.aioe.org/comp.os.ms-windows.programmer.win32
well i have been scrolling down and looking into some of the messages and used the search function but didn't come up with something..

mayby you can post some code for us ?

keywords i used:
capture key
key press
key pressed
SetWindowshookEx
Here's something I rigged together using <windows.h>'s GetKeyState() function:
1
2
3
4
5
6
7
8
9
10
11
int getKey(){
	int buttonpressed = 0;
	while (!buttonpressed){
		for (int i = 0; i < 255; i++){
			if (GetKeyState(i) < 0){buttonpressed = i;}
		}
	}
	while (GetKeyState(buttonpressed) < 0){;}
	return buttonpressed;
}

It doesn't play nicely with cin, it only gets one key at a time, and it probably eats up a lot of cycles. It's worse than a lot of alternatives, but it's better than nothing.
Topic archived. No new replies allowed.