Remote Copy/paste
-
I am trying to get a commercial program to copy it's text file to the clipboard. This code activates the correct window, brings it to the foreground and processes the mouse clicks: input.mi.dx = 950; input.mi.dy = 300; SetCursorPos(input.mi.dx, input.mi.dy); SetForegroundWindow(commercialWindowHandle); 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)); I have verified that the above code works all the time ... but the following code sometimes works ... mosttimes doesn't !!! : SendKeys.Send("^{a}"); // Select all text SendKeys.Send("^{c}"); // Copy to clipboard (It would also be nice if i could set the mouseDown and mouseUp relative to the foreground window instead of to the absolute screen but that is not my primary concern right now) Thanks in advance for any insight. -- modified at 19:38 Monday 20th February, 2006
-
I am trying to get a commercial program to copy it's text file to the clipboard. This code activates the correct window, brings it to the foreground and processes the mouse clicks: input.mi.dx = 950; input.mi.dy = 300; SetCursorPos(input.mi.dx, input.mi.dy); SetForegroundWindow(commercialWindowHandle); 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)); I have verified that the above code works all the time ... but the following code sometimes works ... mosttimes doesn't !!! : SendKeys.Send("^{a}"); // Select all text SendKeys.Send("^{c}"); // Copy to clipboard (It would also be nice if i could set the mouseDown and mouseUp relative to the foreground window instead of to the absolute screen but that is not my primary concern right now) Thanks in advance for any insight. -- modified at 19:38 Monday 20th February, 2006
Try SendWait instead of Send. Also, if that doesn't work, make a call to Application.DoEvents after each SendKeys.SendWait call.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango
-
Try SendWait instead of Send. Also, if that doesn't work, make a call to Application.DoEvents after each SendKeys.SendWait call.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango
Thanks for the suggestions, Judah I tried them all ... but none worked. Surprisingly, this DID work ... the code has been working 100% of the time so far (knock on wood): int pauseTime = 100; System.Threading.Thread.Sleep(pauseTime); SendKeys.Send("^(a)"); SendKeys.Send("^(c)"); It appears that the commercial program just needed some time between the mouse simulation and the keyboard simulation. Surprise! Surprise!