Thread: Monitor Mouse Clicks

  1. #1
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30

    Wink Monitor Mouse Clicks

    Hi,

    I would like to monitor mouse clicks, i.e whenever the left mouse button is pressed i know about it.

    But i'm just abit lost as where to start, i havent coded anything like this before, could some point me in the right direction.

    Thanks for your time.
    In times of war, shoot!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Shall we guess the OS/Compiler you're going to use to attempt this?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Sorry, my fault.

    Windows XP, and Microsoft Visual c++ compiler.
    In times of war, shoot!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you using the MFC library, the native Windows API or some other library to handle your graphics?

    In native windows the message is VM_LBUTTON_DOWN or VM_RBUTTON_DOWN.
    http://msdn2.microsoft.com/en-us/library/ms645607.aspx

    In MFC, use CWnd::OnLButtonDown (or OnRButtonDown). http://msdn2.microsoft.com/en-us/lib...9k(VS.80).aspx

    Other libraries obviously have their own way to deal with these things.

    --
    Mats

  5. #5
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Thanks for the reply, not sure which to use.

    Basically i would need the mouse clicks to be monitored outside of the client window, well there wouldn't even be a client window. I want to be able to monitor everytime the user clicks the left mouse button within windows xp. I'm writing an automated test app, i am using a combination of Java robot api and JNI, java does not support mouse click monitoring outside the VM, so i have gone native.
    In times of war, shoot!

  6. #6
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Thanks, using windows programming i can now monitor left clicks within the client window. But now i need to monitor them outside of the client window. Hopefully i can do this?
    Last edited by mmarab; 09-03-2007 at 07:28 AM.
    In times of war, shoot!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I beleive you can create a handle for the desktop itself, and using that you should be able to "see" mouseclicks all over.

    --
    Mats

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    But now i need to monitor them outside of the client window.
    SetCapture.

    Moved to windows.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Thank you for your help.

    I have been experimenting with HOOKPROC. I will also look into SetCapture. Using either of these i think my problem will be solved.

    I have tried googling my next question but with no luck, i dont think i am using the correct terminology, but basically i was wondering if i could open the application i am testing within the application i am writing. Is this possible?
    In times of war, shoot!

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mmarab View Post
    Thank you for your help.

    I have been experimenting with HOOKPROC. I will also look into SetCapture. Using either of these i think my problem will be solved.

    I have tried googling my next question but with no luck, i dont think i am using the correct terminology, but basically i was wondering if i could open the application i am testing within the application i am writing. Is this possible?
    Yes, ShellExecute or CreateProcess will create a new process that your current process is "the owner of".

    --
    Mats

  11. #11
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Cheers for your help.

    I have a question concerning the following lines of code:

    Code:
    hinstDLL = LoadLibrary((LPCTSTR) "c:\\windows\\sysmsg.dll"); 
    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "SysMessageProc");
    These two lines of code are from the MSDN website, i am confused with them though, firstly the .dll "c:\\windows\\sysmsg.dll" does not exist, i cant find it in that directory.

    Also "SysMessageProc", is this a method i should implement in my code, or is this a method within the .dll .

    Thanks Again.
    In times of war, shoot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Balloon tip question: Trap when the user clicks on "X"
    By Joelito in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2005, 10:35 PM
  2. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 07:25 PM
  3. Locating clicks in the Scrollbars
    By artelo in forum Windows Programming
    Replies: 1
    Last Post: 10-11-2003, 04:09 AM
  4. Replies: 6
    Last Post: 07-27-2002, 01:24 AM
  5. Replies: 1
    Last Post: 06-06-2002, 04:17 PM