This program will get X, Y position of mouse on screen each 1 second
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Threading;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
while (true)
{
// New point that will be updated by the function with the current coordinates
Point defPnt = new Point();
// Call the function and pass the Point, defPnt
GetCursorPos(ref defPnt);
// Now after calling the function, defPnt contains the coordinates which we can read
Console.WriteLine("X = " + defPnt.X.ToString());
Console.WriteLine("Y = " + defPnt.Y.ToString());
Thread.Sleep(1000);
}
}
// We need to use unmanaged code
[DllImport("user32.dll")]
// GetCursorPos() makes everything possible
static extern bool GetCursorPos(ref Point lpPoint);
}
}
Source