How to set mouse cursor position from console application in C #?

I found many articles on how to set the mouse position in a C # windows forms project - I want to do this in a console application. How can I set the absolute mouse position from a C # windows console application?

Thanks!

Hint: This is not Console.setCursorPosition, which only sets the position of the text cursor in the console.

+6
source share
3 answers

In your console application, add a link to System.Windows.Forms.dll and use the other methods that you read about. Choosing a console vs windows exe only affects the PE header (and possibly the default code template, but you can trivialize it); you can still use the full framework in the exe console.

The mouse you want to control is in the windows, not in the console.

+3
source

This is an old thread, but you can do it to complete it ...

use System.Runtime.InteropServices; [DllImport("user32.dll")] static extern bool SetCursorPos(int X, int Y); 

then in the method any position you want, for example.

  SetCursorPos(500, 500); 
+3
source

You can just assign Cursor.Position .

However, in a console application, you will need to add links to WinForms assemblies, because console application projects do not include WinForms links by default.

You will need to add System.Windows.Forms and System.Drawing in order to access the Point class.

+2
source

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


All Articles