Mouse movement using C #

I have a two-dimensional array with coordinates, and I want to make the mouse movement a specific pattern created by these coordinates in a WPF application. Could you help me? I tried the Cursor class, but that will not work. Obviously I'm doing something wrong.

private void SetPosition( int a, int b) { this.Cursor = new Cursor(Cursor.Current.Handle); Cursor.Position = new Point(a, b); } 

This is the method that I use a and b from an array. thanks in advance!

PS this method is inside an event that fires 20 times per second.

+4
source share
2 answers

I'm not quite sure if there is a better way to do this in WPF (it seems that the code you are using is targeting WinForms), but using Platform Invoke on SetCursorPos seems to do the trick:

 private void SetPosition(int a, int b) { SetCursorPos(a, b); } [DllImport("User32.dll")] private static extern bool SetCursorPos(int X, int Y); 
+9
source

You must use SendInput

http://inputsimulator.codeplex.com/ makes it somewhat easy

+3
source

Source: https://habr.com/ru/post/1381934/


All Articles