Sign in to follow this  

Message peeking problem

This topic is 4747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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>

Share this post


Link to post
Share on other sites
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 :))

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

This topic is 4747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this