How can i Simulate mouse clicks and such on a Minimized window or ,,,

Im having a hard time figuring out how i can simulate mouse clicks and such in a window that is minimized or not currently active. Incase i butchered my question im wanting my mouse to be able to click and stuff without actually using the mouse.

For example say im browsing the web,I would like my program to be able to be clicking inside of another application at the same time im browsing or doing whatever it is.

How can i accomplish this? Is all i can find is the same old movemouse and setcursorpos stuff.. as we know that requires the use of your actual mouse/Cursor.

I appreciate any help with this. THank you in advance

Comments

  • I suspect that sending the mouse clicks is the easy part - you just need to send the appropriate windows messages. Knowing what mouse clicks to send and where to send them to could be harder.
    What do you know about the other application?
    Did you write the other application yourself?
    Will the application sending the mouse clicks start the other application, or will the other application already be running? If there are multiple instances of the other application?
    How will you know the location of the simulated mouse click? ie the (x,y) co-ordinates.
  • This is basically the same issue as automated GUI testing and there are no universal solutions. Doing this on a minimized window is prohibitively difficult if not impossible; i.e. how do you call an event listener at mouse coordinates that do not correspond to anything. Im not aware of any solutions that do this ( though my insight into this area is limited). You could create a shim between your even handlers and the methods they invoke, driving them via a script while under test, and by user input under normal conditions but that requires modification of the program you're automating and is very unlikely to be worth the effort of implementation.

    Could you go into more detail about your use case?
  • Doing this on a minimized window is prohibitively difficult if not impossible.
    It can be done. (I have done it). Faking clicks on a minimised window does work, and the window receives the clicks at the correct location. The problem is knowing which window to send the clicks to. For example, create a Delphi app with a blank form and a single button, and have event handlers to handle mouse down/up and click events. Use this as the taret application you want to click on. Then create the "clicker" application to send clicks to the target application. You can get the handle for the target app's form easily enough and mouse messages sent there are handled correctly even when the form is minimized. This doesn't let you click on the button though. You need to get a handle for the button and send it muse essages directly. This gives you the problem of getting the handle for the button or other object you actually want to click, and any real-world app has many controls and they are often not static. Getting the appropriate handles and keeping them up to date can get tedious but it is possible.
    I haven't tried using this approach to click on graphics controls that do not have a handle. Perhaps I'll try that.
  • SalmiSoft wrote:
    It can be done. (I have done it). Faking clicks on a minimised window does work, and the window receives the clicks at the correct location. The problem is knowing which window to send the clicks to. For example, create a Delphi app with a blank form and a single button, and have event handlers to handle mouse down/up and click events. Use this as the taret application you want to click on. Then create the "clicker" application to send clicks to the target application. You can get the handle for the target app's form easily enough and mouse messages sent there are handled correctly even when the form is minimized. This doesn't let you click on the button though. You need to get a handle for the button and send it muse essages directly. This gives you the problem of getting the handle for the button or other object you actually want to click, and any real-world app has many controls and they are often not static. Getting the appropriate handles and keeping them up to date can get tedious but it is possible.
    I haven't tried using this approach to click on graphics controls that do not have a handle. Perhaps I'll try that.
    This is basically the same issue as automated GUI testing and there are no universal solutions. Doing this on a minimized window is prohibitively difficult if not impossible; i.e. how do you call an event listener at mouse coordinates that do not correspond to anything. Im not aware of any solutions that do this ( though my insight into this area is limited). You could create a shim between your even handlers and the methods they invoke, driving them via a script while under test, and by user input under normal conditions but that requires modification of the program you're automating and is very unlikely to be worth the effort of implementation.

    Could you go into more detail about your use case?

    Thank you both of you for your replies, they are very informative.

    So what i would like to eventually do is do a sort of search for a specific Bitmap(Maybe a specific bitmap within another bitmap?) and then move the mouse to that position and perform a click. What do you guys think of that? Like a sort of color bot type application?

    Please i would love to here more from you guys, I hope to hear back from you guys soon.

    PS - Is SendMessage appropiate for this type of task? SendInput? Im not sure what to use? Let me know fella's
  • DatSik wrote:
    So what i would like to eventually do is do a sort of search for a specific Bitmap(Maybe a specific bitmap within another bitmap?) and then move the mouse to that position and perform a click. What do you guys think of that? Like a sort of color bot type application?
    ...
    PS - Is SendMessage appropiate for this type of task? SendInput? Im not sure what to use? Let me know fella's
    Let's start with the easy question. yes, SendMessage (or PostMessage) is the way to go (assuming you want to click on a 3rd-party application rather than something you wrote yourself. If you want to click on one of your own apps then simulating mouse clicks may not be the best way to accomplish your aims.) You would need code something like this:
    sendMessage(FhTarget,WM_LBUTTONDOWN, 0, MakeLParam(ClickX, ClickY));
        sendMessage(FhTarget,WM_LBUTTONUP,   0, MakeLParam(ClickX, ClickY));
    
    Where
    FhTarget is the handle of the window you want to click on.
    ClickX and ClickY are the X & Y co-ordinates of where you want to click. (0,0) would be the top left of the window whose handle you supply in FhTarget.
    I am assuning you don't need anything for WPARAM, which is why I show 0. This would change if you need to click with shift or control keys, or other mouse buttons.

    Of course this raises the supplementary issue of getting the handle of the window you wish to click. Do you know how you will do that? It is the reason I asked what you know about the other application, if you wrote it yourself, and how it will be started.

    The harder question is how to recognize the bitmap (or part of a bitmap) you wish to click. Do you have any plan for doing that? What do you know about the bitmap? I think this part of the task could be the most difficult part.
Sign In or Register to comment.