@@ -97,6 +97,7 @@ private static MouseInput GetAbsoluteMouseInput(int x, int y)
9797 input . dx = x ;
9898 input . dy = y ;
9999 input . dwFlags = ( int ) MouseFlags . MOUSEEVENTF_MOVE_NOCOALESCE ;
100+ input . mouseData = 0 ;
100101 input . time = 0 ;
101102 return input ;
102103 }
@@ -105,19 +106,27 @@ private static MouseInput GetVirtualMouseInput(int x, int y)
105106 {
106107 MouseInput input = new MouseInput ( ) ;
107108 input . type = ( int ) ( InputType . INPUT_MOUSE ) ;
108- input . dx = ( x * 65536 ) / GetSystemMetrics ( SM_CXSCREEN ) ; ;
109- input . dy = ( y * 65536 ) / GetSystemMetrics ( SM_CYSCREEN ) ; ;
109+ input . dx = ( x * 65536 ) / GetSystemMetrics ( SM_CXSCREEN ) ;
110+ input . dy = ( y * 65536 ) / GetSystemMetrics ( SM_CYSCREEN ) ;
110111 input . dwFlags = ( int ) ( MouseFlags . MOUSEEVENTF_MOVE_NOCOALESCE | MouseFlags . MOUSEEVENTF_VIRTUALDESK ) ;
112+ input . mouseData = 0 ;
111113 input . time = 0 ;
112114 return input ;
113115 }
114116
115- public static void MouseMoveTo ( int x , int y , MouseButtons buttons )
117+ public static void MouseMoveTo ( int x , int y , MouseButtons buttons , bool buttonUp = false )
116118 {
117119 MouseInput input = GetVirtualMouseInput ( x , y ) ;
118120 MouseFlags flags = ( MouseFlags ) input . dwFlags ;
119121 flags |= MouseFlags . MOUSEEVENTF_MOVE | MouseFlags . MOUSEEVENTF_ABSOLUTE ;
120- flags = AddMouseDownFlags ( flags , buttons ) ;
122+ if ( buttonUp )
123+ {
124+ flags = AddMouseUpFlags ( flags , buttons ) ;
125+ }
126+ else
127+ {
128+ flags = AddMouseDownFlags ( flags , buttons ) ;
129+ }
121130 input . dwFlags = ( int ) flags ;
122131 SendInput ( input ) ;
123132 Application . DoEvents ( ) ;
@@ -132,8 +141,9 @@ public static void MouseDragDrop(Point start, Point end, int step, MouseButtons
132141 MouseDown ( start , buttons ) ;
133142 Application . DoEvents ( ) ;
134143 Thread . Sleep ( DragDelayDrop ) ;
135- MouseDragTo ( start , end , step , buttons ) ;
144+ MouseDragTo ( start , end , step , buttons , true ) ;
136145 Thread . Sleep ( DragDelayDrop ) ;
146+ MouseDragTo ( end , end , step , buttons , true ) ;
137147 MouseUp ( end , buttons ) ;
138148 Application . DoEvents ( ) ;
139149 Thread . Sleep ( DragDelayDrop ) ;
@@ -145,7 +155,7 @@ public static void MouseMoveTo(Point start, Point end, int step)
145155 MouseDragTo ( start , end , step , MouseButtons . None ) ;
146156 }
147157
148- public static void MouseDragTo ( Point start , Point end , int step , MouseButtons buttons )
158+ public static void MouseDragTo ( Point start , Point end , int step , MouseButtons buttons , bool finishWithButtonUp = false )
149159 {
150160 // Interpolate and move mouse smoothly over to given location.
151161 double dx = end . X - start . X ;
@@ -157,9 +167,11 @@ public static void MouseDragTo(Point start, Point end, int step, MouseButtons bu
157167 int tx = start . X + ( int ) ( ( dx * i ) / length ) ;
158168 int ty = start . Y + ( int ) ( ( dy * i ) / length ) ;
159169 MouseMoveTo ( tx , ty , buttons ) ;
170+ Thread . Sleep ( 1 ) ;
171+ Application . DoEvents ( ) ;
160172 }
161173
162- MouseMoveTo ( end . X , end . Y , buttons ) ;
174+ MouseMoveTo ( end . X , end . Y , buttons , finishWithButtonUp ) ;
163175 }
164176
165177 public static void MouseWheel ( AutomationWrapper w , int clicks )
0 commit comments