Thread: Move the cursor and click there

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005

    Move the cursor and click there

    Could anyone post a full example code if Id like my program to move my mouse to the coords 100,100 and make it click there?

    Thanks a lot.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001

    If this is a Windows program, post your question on the Windows forum. It's easy to do (assuming you already have the code to create the window), but I don't remember the functions off the top of my head... and I don't have my Petzold book with me. There's a Windows API function to move the cursor, and there's a function to send a mouse-click message to your program.

    If you're looking for an easy way to automate an existing application (without using WinAPI, C, or C++) check out WinBatch. It took me about a day to learn WinBatch... I've been fooling around with the WinAPI off & on for years, and I'm still a beginner!
    Last edited by DougDbug; 12-21-2005 at 02:44 PM.

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Well, yeah I posted wrong then.
    Its a windows program.
    Just post here instead of making 2 threads.

    I know its SetCursorPos or something, but never really understood the "POINT" function.
    Its like you have the x and the y variables in one.
    Dont know how to do that.

    And I dont know how to make it actually click.

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    What have you got so far?

    A POINT is a structure of two integers, one for the x and one for the y coods. Remember that the coords can be relative to the top left corner of the screen or top left of the window capturing the mouse. ClentToScreen() or ScreenToClient() will convert.

    POINT ptMouse;


    //convert to or from client / screen coords

    Send mouse msg WM_LBUTTONDOWN with SendMessage(). May find MAKELPARAM() macro useful (windows.h)

    There has been code posted here, try a search.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002

Popular pages Recent additions subscribe to a feed