How can you detect if a key is pressed when the window isn't active?

Started by
5 comments, last by Sydius 22 years, 6 months ago
Long story short, I''m trying to put togather a little macro program... Well, incase you can''t guess, a macro program just plain doesn''t work when you can''t use the macros while other programs are the active ones. IE if im playing a game, and I hit the macro, nothing happens since the macro program is runing in the background, and the keypress was only sent to the game... So how do I detect key presses no matter what program is the active one? Someone told me that it is POSSIBLE to do it with the Win32 API... so does anyone know? I can''t use DInput (Dev-C++ refuses to work with DX)... Any help would be greatly apreciated :-)
Advertisement
Use a low level keyboard hook.

[Resist Windows XP''s Invasive Production Activation Technology!]
Uhm ok... how would I go about doing that? (I have no clue heh)
Not sure if I can help but I make a program that read if the insert key in the num pad is push and if is push he emulate the key pause. I use the program on Half-life and is work but if i emulate a other key Half-life think is the pause key. I think that because Half-life use direct input but I am not sure.

So to see if a key is pressed I use GetAsyncKeyState command and you need i think Winuser.h. You can find all the info at this address:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/keybinpt_1x0l.asp

I make my program in c++ builder and put a timer to check if a key is pressed


PS: sorry for my poor english
Try using SetWindowsHookEx
LONG LIVE DOS!
Hi. Create a timer and call GetAsyncKeyState in the timerprocedure.

This topic is closed to new replies.

Advertisement