My application is an automation for another app.
I want to move the cursor to a specific position on the screen. The problem i am having is that when the wpf application isn't the foreground application, the cursor doesn't move. So, basically, the app i am trying to make an automation to is displayed to the user and i want to have a process in the background that will move the cursor automatically.
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process proc in processes)
{
IntPtr handle = proc.MainWindowHandle;
RECT Rect = new RECT();
GetWindowRect(handle, ref Rect);
if (Rect.left == 0 || Rect.right == 0 || Rect.top == 0 || Rect.bottom == 0)
continue;
Int32 Y = Rect.top + 50;
Int32 X = (Rect.right - Rect.left) / 2;
POINT p = new POINT();
p.x = X;
p.y = Y;
ClientToScreen(handle, ref p);
SetCursorPos(p.x, p.y);
}
It only works if the wpf application is the app that is currently displayed on the screen.