Click Click
-
I have succeeded in getting my code to successfully do mouse clicks on a commercial program, running at a specific screen location, using this code: SetForegroundWindow(targetWindowHandle); input.type = INPUT_MOUSE; input.mi.dx = 900; input.mi.dy = 50; input.mi.mouseData = 0; input.mi.time = 0; input.mi.dwFlags = 0; input.mi.dwExtraInfo = 0; SetCursorPos(input.mi.dx, input.mi.dy); input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTDOWN); resSendInput = SendInput(1, ref input, Marshal.SizeOf(input)); input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_LEFTUP); resSendInput = SendInput(1, ref input, Marshal.SizeOf(input)); The problem is, of course, if the window is moved, the clicks miss. I would love to be able to do the clicks relative to position 0,0 of the window pointed at by targetWindowHandle instead of relative to position 0,0 of the screen. (I hope that statement makes sense to you guys.) Any suggestions? :rolleyes: Thanks. :rolleyes: -- modified at 20:11 Wednesday 22nd February, 2006
-
I have succeeded in getting my code to successfully do mouse clicks on a commercial program, running at a specific screen location, using this code: SetForegroundWindow(targetWindowHandle); input.type = INPUT_MOUSE; input.mi.dx = 900; input.mi.dy = 50; input.mi.mouseData = 0; input.mi.time = 0; input.mi.dwFlags = 0; input.mi.dwExtraInfo = 0; SetCursorPos(input.mi.dx, input.mi.dy); input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTDOWN); resSendInput = SendInput(1, ref input, Marshal.SizeOf(input)); input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_LEFTUP); resSendInput = SendInput(1, ref input, Marshal.SizeOf(input)); The problem is, of course, if the window is moved, the clicks miss. I would love to be able to do the clicks relative to position 0,0 of the window pointed at by targetWindowHandle instead of relative to position 0,0 of the screen. (I hope that statement makes sense to you guys.) Any suggestions? :rolleyes: Thanks. :rolleyes: -- modified at 20:11 Wednesday 22nd February, 2006
for those interested ... The solution was rather trivial after i found "GetWindowRect" in User32: public struct RECT { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll")] public static extern int GetWindowRect(int hwnd, ref RECT rc); // Get the target window's screen coordinates RECT rect = new RECT(); int hwnd = GetWindowRect((int)targetWindowHandle, ref rect); Persistence pays ... :cool: --- -- modified at 15:34 Thursday 23rd February, 2006