in c++ how do i detect the state of a given key no mater wha

Programming, for all ages and all languages.
Post Reply
Scarberry

in c++ how do i detect the state of a given key no mater wha

Post by Scarberry »

how do i detect the state (up, down) of a given key and/or mouse button, no matter which program is in focus?


thanks
anubis

Re:in c++ how do i detect the state of a given key no mater

Post by anubis »

Thinking that u r using widows as ur development environment. U can use the SetWindowsHookEx() function to trap the user inputs and then check for the states.

Check THIS for more info on hooks. Or u can always search for hooks in MSDN.

Hope that it helps.

_Anubis_
ark

Re:in c++ how do i detect the state of a given key no mater

Post by ark »

My memory on this is a little rusty, so I'm not 100% sure about this, but depending on your needs GetAsyncKeyState may also be easier than using a keyboard hook.
Ozguxxx

Re:in c++ how do i detect the state of a given key no mater

Post by Ozguxxx »

getasynckeystate uses lots of cpu time, assuming you are implementing a keylogger, your program will be detectable... Hooking is much more useful, and in some sense it is much more easier and also you can never leave a key behind with hooking...
Post Reply