How do i use SetWindowsHookEx(WH_MOUSE to detect global mouse clicks please help

This is a discussion on How do i use SetWindowsHookEx(WH_MOUSE to detect global mouse clicks please help within the Windows Programming forums, part of the Platform Specific Boards category; I need help with detecting global mouse clicks. Here is a program i made using SetWindowsHookEx(); but it only detects ...

  1. #1
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Question How do i use SetWindowsHookEx(WH_MOUSE to detect global mouse clicks please help

    I need help with detecting global mouse clicks. Here is a program i made using SetWindowsHookEx(); but it only detects mouse clicks in my program. I add the program i got so far. Please tell me what i need to add to make it detect global mouse clicks.
    Attached Files Attached Files
    int a; don't make a program without it.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: How do i use SetWindowsHookEx(WH_MOUSE to detect global mouse clicks please help

    Originally posted by Josh Kasten
    I need help with detecting global mouse clicks. Here is a program i made using SetWindowsHookEx(); but it only detects mouse clicks in my program. I add the program i got so far. Please tell me what i need to add to make it detect global mouse clicks.
    I responded to your earlier post...

    You need to create a dll with the hook procedure in it and usually a few exported funcs to launch and kill the hook....

    Then, as the function you are using as the callback exists in other processes, you need a method to send the info back to your program.....I like to use a MailSlot as its supported across all win platforms and is easy to use...

    Go to the other reply I gave and see the link I gave

  3. #3
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Unhappy can't figer out how it works

    I thank you for telling me about your program but how does it get keypresses for the .dll? i see that they go into a file but i've never seen the file. I don't think the program is working right. you sould just have the key presses just be outputed to the program. Could you explane how this program works better or make the program simpler?
    int a; don't make a program without it.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: can't figer out how it works

    Originally posted by Josh Kasten
    I thank you for telling me about your program but how does it get keypresses for the .dll? i see that they go into a file but i've never seen the file. I don't think the program is working right. you sould just have the key presses just be outputed to the program. Could you explane how this program works better or make the program simpler?
    I dont actually use a file.....I use a mailslot...this is an address in the computer all instances of my dll can write to, and my main program will read it.......When you create a keyhook like that, the dll code is injected into the process space of any app recieving a keystroke message...therefore all file handles and such are usless ( as a handle is relevant to the process that owns it and it cant be transfered as you dont know the app that's going to use the handle).

    To use the app, start the exe...and proess start.....the program will then sit there and wait for port 5110 be connected to.....once a connection is made (you can use telnet - "open localhost 5110"), the hook is launched and the dll code starts sending keystroke info to the mailslot.......once a number of chars atre recieved by the exe (I think I programmed it for 10), it sends the info to the connected program (If you used telnet, the keystrokes will appear there on screen)

  5. #5
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Question help on Mailslot

    I made a program that uses a mouse hook and Mailslot to put the clicks in it but i don't think its reading the mailslot right. It looks as if it just goes in a loop. How to i get it to just stay at the begining of the mailslot and read and wright there? I add the source code so you can take a look at it and see whats wrong
    Attached Files Attached Files
    int a; don't make a program without it.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: help on Mailslot

    Originally posted by Josh Kasten
    I made a program that uses a mouse hook and Mailslot to put the clicks in it but i don't think its reading the mailslot right. It looks as if it just goes in a loop. How to i get it to just stay at the begining of the mailslot and read and wright there? I add the source code so you can take a look at it and see whats wrong
    Dont think of a mailslot as a file.....you dont need any form of file pointer...


    From my code...
    Code:
    GetMailslotInfo(hMailslot,&dwMaxsize,&dwSize,
                &dwCount,&dwTimeout);//See what is in the mailslot
    
            if(dwSize==MAILSLOT_NO_MESSAGE){
                Sleep(500);
                continue;//If nothing, wait half second & retry
            }
    
            ReadFile(hMailslot,szReadBuff,dwSize,//read info
                &dwRead,NULL);
            szReadBuff[dwRead] = NULL;
    You just call the GetMailSlotInfo() api, and if there is no message, you issue a continue statement to jump to the top of the loop....If there is a message, you call ReadFile().......this then takes the message and there's no need to mess with a pointer....

    BTW..I used the Sleep() because I was in a seperate thread to do this, and the loop it existed in had no other purpose....you may wish to ommit this as you are in the message loop as it will not be good for the timeing of your prog

  7. #7
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Smile Thanks for all the help

    Thanks for all the help. I got the mailslot to work thanks
    int a; don't make a program without it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Identifying mouse used with Global mouse hooks
    By Chillance in forum Windows Programming
    Replies: 4
    Last Post: 02-15-2009, 07:42 AM
  2. Windows Hooks for global mouse detection
    By JJFMJR in forum Windows Programming
    Replies: 8
    Last Post: 08-12-2008, 08:04 AM
  3. Monitor Mouse Clicks
    By mmarab in forum Windows Programming
    Replies: 10
    Last Post: 09-04-2007, 04:52 AM
  4. Replies: 2
    Last Post: 05-31-2006, 06:57 PM
  5. Replies: 1
    Last Post: 06-06-2002, 04:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21