Advertisement

Keypresses

Started by February 15, 2000 04:11 AM
2 comments, last by xstreme2000 24 years, 10 months ago
Can someone post up some example code for getting keypresses when the app is not active thanks!
Off the top of my head....

Assuming you are using windows and not DI, you will need to add a hook function into the hook chain with SetWindowsHookEx and use the type id WH_CALLWNDPROC to see all messages before they get sent to their proper destination. Then you can do as you will with them. If you do use hooks though, be sure to remove them after you have finished.

Sorry I haven''t any code available as I have never done this myself but anyhow have a look in the Win32 SDK.
Advertisement
GetAsyncKeyState(KeyCode) will inform you if some key is pressed. Have a loop checking for the keys you''re intrested.

c''ya
... LEMMINGS ... LEMMINGS ... LEMMINGS ... LEM..... SpLaSh!...Could this be what we stand like before the mighty One?Are we LeMmIngS or WhAt!? ;)
You don''t want to make a loop like Harvester suggested because your program will steal all the cpu resources from other programs so that everything will be extremely slow.

The best way to go is with Hooks as STG suggested, they are really easy to work with. Just look it up in the VC++ manual.

This topic is closed to new replies.

Advertisement