SendKeys.send format to send Ctrl-C = SendKeys.Send("^(C)"); ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DOSrelic
    New Member
    • Sep 2006
    • 13

    SendKeys.send format to send Ctrl-C = SendKeys.Send("^(C)"); ?

    Cos I got the right window but nothing is copied to the Clipboard altho text is highlighted! Here is a little snippet from the method:
    Code:
    internal void getHighlightedText()
            {
     // why can it not copy?
                string fff = Clipboard.GetText();
                AttachThreadInput(_activeThreadId, _myProcessId, true);
                SetForegroundWindow(_hWnd);
                SendKeys.Send("^(C)");
                fff = Clipboard.GetText();
                AttachThreadInput(_activeThreadId, _myProcessId, false); //release the attachment
                if (Clipboard.ContainsText())
                {
    But it doesn't? Any ideas why as the correct windows get highlighted?
    Your knowledge and experience will be greatly appreciated, cheers.
    Last edited by DOSrelic; Feb 9 '10, 01:34 AM. Reason: wrong snippet
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Don't try to do it through keystroke trickery. Just use the clipboard class and send what you want to the clipboard.
    Provides methods to place data on and retrieve data from the system Clipboard. This class cannot be inherited.

    Comment

    • DOSrelic
      New Member
      • Sep 2006
      • 13

      #3
      Hi tlhintoq, yes and that's what I'm trying to do. Get the other app to utilise the clipboard to copy the highlighted text! If I go ctrl-C then hit the hotkey it works fine but I can't seem to send the ctrl-c keypresses to the foremost window to simulate the copy to clipboard command, any idea why?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        "The other app" ?

        So you're not trying to have your application send to the clipboard...
        You're trying to programmaticall y control someone else's application, and make it think a user has pressed control-c.

        Does that sound like a correct clarification?

        My first guess is that the *window* has nothing to send to the clipboard.
        But maybe a control *in* the window does. Forms don't generally have any content to go to the clipboard, but a textbox for example has a .Text property that has text that can go on the clipboard.

        Comment

        • DOSrelic
          New Member
          • Sep 2006
          • 13

          #5
          Almost correct but I am trying to modify the selected text as per the user's request via a hotkey. Much like wordweb can access anything you have highlighted anywhere but it does not seem to be getting the ctrl-c sequence?The theory being that if I send ctrl-c to the user's current window it would automatically copy the highlighted text in the foreground window to the clipboard so my app can then work on it. Am I sending the correct string to SendKeys? If I am then the problem must lie elsewhere, right?

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Am I sending the correct string to SendKeys?
            Yah got me. Make a quickie Forms app of your own with a text box to test it against. That way you can debug both ends of the process. When your test app receives a keypress then it can tell you want it got and so on.

            Otherwise you are shooting an arrow at a target - in the dark.

            Comment

            • DOSrelic
              New Member
              • Sep 2006
              • 13

              #7
              Cheers tlhintoq. Thanks for your help again.

              Comment

              Working...