Capture mouse click (hook)

Hi there,

I am a beginner at C++ so I don't really know the syntax yet. However, I have written a piece of code yet which captures all keyboard input (using GetAsyncKeyState) and creates a socket to transfer the information. Now I need to capture any mouse click (so even if the program is out of focus). How can I do this? I asume I have to use the setWindowsHookEx function, but I don't know how.
I am using Borland as a compiler, writing for Windows XP. If neccessary, I can post the other code so the 'mouse-click-code' can be implemented at once.
I hope you guys can help this ambitious newbie!
Hmm does nobody know how to fix this? There should be a way to track mouse clicks, even when the program isn't focused.
closed account (Lv0f92yv)
I hesitate to ask why you're interested in doing this...
Desh +1. The reason no one has responded to you Cyroq is that you are new and your first post is about hooking input. If you were to build a reputation even by simply helping other users then we would be more inclined to answer your questions.

In the interests of education and enlightenment and to show that we are not just abunch of paranoid elitists I will point you to an excellent book that would help you in your endevor:

http://www.amazon.com/Rootkits-Subverting-Windows-Greg-Hoglund/dp/0321294319/ref=sr_1_1?ie=UTF8&s=books&qid=1273503724&sr=8-1

Although the primary focus is security this is hands down the best book I've read for understanding the inner workings of the Windows NT family.

EDIT: On a sidenote yes you were correct in your assumption that setWindowsHookEx is a function that could accomplish this task but there is more to it. That extra is what I won't help you with in because of the reason I mentioned above.
Last edited on
I'm so sorry it was looking I wanted to abuse this forum, I'm really am not! I will shortly explain why I need these functions.
Maybe you have heard about WorkPace, a program that forces users to take a break every hour. For my study I am designing a new method to stimulate computer users to take a break once in a while, and to do this I need to track the activity (which is keyboard and mouse input). I managed to capture global keyboard input but still need to capture global mouse activity. I don't even need to know at what coordinates the mouse clicks, only if it clicks or not. Unfortunately I don't have much time to create this code, so I hope somebody can help me with an example of how to implement the mouse hook.
Although I don't have much experience in C++, I am willing to learn! :)
Take a read through the Windows Hooks section at MSDN:
http://www.google.com/search?btnI=1&q=msdn+Windows+Hooks

If all you want to know is idle times, check out the WH_FOREGROUNDIDLE hook.
If you want to track system input, use the WH_JOURNALRECORD hook.

Good luck!
Wait a minute! I'd like to know more about this WorkPace idea. It sounds like a great concept that my boss should know about.

I even have an idea for a sequel: BeerPace! A computer program designed to help those poor unfortunate souls that may not even realize that their beer consumption has fallen dangerously low. Includes links to its companion website... Guzzle.
closed account (Lv0f92yv)
BeerPace

+1 for laughs.

@Cyroq, this actually seems like an interesting idea - and I did not mean to come across too harsh in my initial response. Good luck!
Hehe, BeerPace. That would be a nice school project!
I forgot to tell that the project is not about software itself, it is just a medium. In the end of all processes (keyboard input > C++ > Flash > Microcontroller) will be a bureau lamp which indicates with its light how fast you are working.

Unfortunately I don't understand the syntax of C++ that well. I have read through the page Duoas posted but I don't know how to use this. Can somebody give me a hint of how to set this up? Thanks!
Topic archived. No new replies allowed.