Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Remote Copy/paste

Remote Copy/paste

Scheduled Pinned Locked Moved C#
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IceWater42
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • I IceWater42

      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

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      I 1 Reply Last reply
      0
      • J Judah Gabriel 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

        I Offline
        I Offline
        IceWater42
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups