C# – Simulate dragging mouse with SendInput



How I simulate dragging the mouse in Windows apps using C# SendInput. A SendInput download from codeproject.com is used to build functions to drag the left and right mouse.

InputSender Download:
https://www.codeproject.com/Articles/5264831/How-to-Send-Inputs-using-Csharp

private void LeftDrag(Point start, Point end)
{
InputSender.SetCursorPosition(start.X, start.Y);

InputSender.SendMouseInput(new InputSender.MouseInput[]
{
new InputSender.MouseInput
{
dwFlags = (uint)InputSender.MouseEventF.LeftDown

}
});

Thread.Sleep(100);

InputSender.SetCursorPosition(end.X, end.Y);

InputSender.SendMouseInput(new InputSender.MouseInput[]
{
new InputSender.MouseInput
{
dwFlags = (uint)InputSender.MouseEventF.LeftUp
}
});
}