how i move the mouse cursor . and create left, right and double cliks using visual c++
i m new to visual c++

tnx for this information but i want move the mouse cursor in visual c++ ennviorment

I know what you want, my reply was half jokingly saying that you should leave such things to the user, seeing as how the mouse is a user interface peripheral.

I would like to handle mouse in Windows. For instance, I want to have some functions
*** gotoxy(x,y)
//then mouse go to (x,y), like you use physical mouse move
*** left_click(), right_click()
//then mouse click
in visual c++

i want to to handle the mouse by hand gestures . so first i need to understand how i control the mouse in visual c++.because latter i also use visual c++ for hand gestures

SendInput() is what you want. And here's an example:

#include <iostream>
#include <windows.h>

int ScreenWidth() { return GetSystemMetrics(SM_CXSCREEN) - 1; }
int ScreenHeight() { return GetSystemMetrics(SM_CYSCREEN) - 1; }

void MoveMouse(LONG x, LONG y)
{
    INPUT in = {
        INPUT_MOUSE,
        {
            x * (65535.0 / ScreenWidth()),  // Map the x,y position to absolute 
            y * (65535.0 / ScreenHeight()), // mouse coords in a [0,65535) range
            0, 
            MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE
        }
    };

    SendInput(1, &in, sizeof in);
}

void RightMouseClick()
{
    INPUT zero = {INPUT_MOUSE, 0};
    INPUT in = zero;

    in.mi.dwFlags  = MOUSEEVENTF_RIGHTDOWN;
    SendInput(1, &in, sizeof in);

    in = zero; // Reset for the key up event
    in.mi.dwFlags  = MOUSEEVENTF_RIGHTUP;
    SendInput(1, &in, sizeof in);
}

int main()
{
    std::cout << "Active screen dimensions: "
              << ScreenWidth() << 'x' << ScreenHeight() << '\n'
              << "Moving mouse to the center...";

    Sleep(1000);
    MoveMouse(ScreenWidth() / 2, ScreenHeight() / 2);

    std::cout << "Done.\nPerforming right mouse button click...";

    Sleep(1000);
    RightMouseClick();

    std::cout << "Done.\n";
}
This article has been dead for over six months. Start a new discussion instead.