Message peeking problem

Started by
7 comments, last by RaptorZero 19 years, 4 months ago
Puf... after a 4 months break in programming I'm going for a warm up again... OK, lets get to busyness: I'm creating a little app that is suposed to get keypresses and mouse clicks outside of it (on the desktop, internet explorer or whatever other program is running). So I got out with two possible aproaches each one with a problem: 1. I handle messages with GetMessage(&msg, NULL, 0, 0) and use GetAsyncKeyState(VK_WHATEVER); to check if the desired key was pressed Problem: The app only gets the keypresses when I'm typing on it 2. I handle messages with PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) and use the same method as above to check key presses. It runs perfectly! (or almost) Problem: When I go to TaskManager (Ctrl + Alt + Del) it says that my app is consuming 100% CPU time O_o (despite there's no performance changes I can notice) So, what do I do? Is it possible to get external keypresses using method 1? or is it possible to use method 2 whitout eating all CPU time? or even does it matters that my app consumes all CPU as long as doesn't cause any performance changes? PS: My app is a win32 dialog based app Thanks for reading till here :) if any source code is required just say it <out for lunch>
error C2065: 'signature' : undeclared identifier
Advertisement
#3: Use a keyboard and mouse hook.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Quote:Original post by antareus
#3: Use a keyboard and mouse hook.


Ok, I've just come from a MSDN article about hooks and it feels like my head is spinning...

Can anyone post any other articles/examples/tutorials about this?

Oh, and one more thing, in the article there's a place where it says "All systemwide hooks and hooks for threads in different applications must reside in DLLs." - that scared me off, does it mean that if I'm gonna put a keyboard hook to watch keypresses my program must have a DLL?

Thanks for the answer (despite being very short :))
error C2065: 'signature' : undeclared identifier
The hook code has to reside in a DLL. After the host program is loaded, it loads the hook DLL. When subsequent applications get the WM_ACTIVATE message, the DLL is loaded into their process space so it can do its monitoring.

Source for an idle monitor DLL - Sadly, thats the extent of my knowledge of hooks. Hopefully someone else has a more complete example.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Oh god, isn't there an easiest way of doing that? :(

It seems like I'm gonna have to learn about programming dlls (I always feared that)

Ok, I'm gonna try to understand how does that dll source code works

In the meanwhile, if someone have any other possibility plz post here!

Thanks a lot for the answers...

[Edited by - RaptorZero on December 17, 2004 9:30:29 AM]
error C2065: 'signature' : undeclared identifier
Well, yeah, its meant for viewing with a web browser. :)
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
One more thing: does it makes things more simple if the keypress detection watches only one specific program?

That is, see if a specific program is running (foobar.exe) and then hook it (or do semething else)

Sry putting this after all those answers but I completely forgot about it.

PS:
Quote:Well, yeah, its meant for viewing with a web browser. :)
sry, i edited my last post before your reply and removed that "its a htm file not cpp"
error C2065: 'signature' : undeclared identifier
I am VERY interested to know why you want to do this, and although I could help you here I am not going to, until I know what you are doing. The kind of thing you are doing is the kind of thing that people would do for adware/spyware. It certainly doesn't sound like it's for a game.

Prove me wrong and I will gladly help you.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
OMG, I'm so sorry I didn't say anything about the reason I was asking for this help...

The proposit of the program is to watch predetermined keypresses in a particular program (a game) in order to activate some benefits... resuming: it's a trainer

I was hoping to create an app to activate some memory modifications and mouse inputs in "GTA: Vice City" - since this isn't an online game, there's nothing wrong in doing it.

I'm sorry I may have passed the idea of a spyware by saying I wanted to watch keypresses on the desktop and etc, but my intention is to play a little with the game's dificulties

If you still don't believe me, you can check out my previous posts, they're all about game programming (that's my area :)).

Once again I apologise for making it look like a spyware or something. If you are still not convinced of my intentions or thinks that what I'm doing is wrong, I can't say much else to make you change your mind, but I still need help about this project and everyone is welcome to post anything that might be usefull here.

[Edited] Already found an way of doing it by using Sleep() at the loop (I had almost forgot about this post) [Edited]

[Edited by - RaptorZero on February 16, 2005 5:11:16 PM]
error C2065: 'signature' : undeclared identifier

This topic is closed to new replies.

Advertisement