简体   繁体   中英

C# Linux Console - Get cursor position

I just changed to linux and I'm trying to make a simple
application with C# console, but I even can't take the console cursor position.


In windows I use:

public Pointer get() {
  Point pos = new Point();
  GetCursorPos(ref pos);
  return pos;
}

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

[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);

But of curse it doesn't work on linux.


How can I do that in linux?

You can use Console.SetCursorPosition

An example would be like this:

Console.Clear(); //this clears the console
Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop); //this sets back to beginning

You can get the current position with this:

var CurrentCursorPositionConsole = Console.GetCursorPosition();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM