public static void CheckIfCursorIsMovingInClient(IntPtr hwnd) { SearchImage.RECT clientPos = new SearchImage.RECT(); GetWindowRect(hwnd, ref clientPos); Point mousePos; GetCursorPos(out mousePos); if (mousePos.X > clientPos.Left && mousePos.Y > clientPos.Top && mousePos.X < clientPos.Right && mousePos.Y < clientPos.Bottom && GetForegroundWindow() == hwnd) { //Console.WriteLine("Mouse is in Window, move outside!"); SetCursorPos(clientPos.Left - 100, clientPos.Top - 100); } }
static extern bool GetClientRect(IntPtr hwnd, out SearchImage.RECT lpRect);
public static extern bool GetWindowRect(IntPtr hwnd, ref SearchImage.RECT rectangle);