C# - Simulate mouse drag with SendInput (codeproject implementation)

Опубликовано: 14 Март 2026
на канале: JFLHV
1,806
8

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

InputSender Download:
https://www.codeproject.com/Articles/...

C# Automation Playlist:
   • C# Automation  

#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);

// added to fix text not always being selected during drag
Thread.Sleep (100);

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