468,727 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

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

DOSrelic
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:
Expand|Select|Wrap|Line Numbers
  1. internal void getHighlightedText()
  2.         {
  3.  // why can it not copy?
  4.             string fff = Clipboard.GetText();
  5.             AttachThreadInput(_activeThreadId, _myProcessId, true);
  6.             SetForegroundWindow(_hWnd);
  7.             SendKeys.Send("^(C)");
  8.             fff = Clipboard.GetText();
  9.             AttachThreadInput(_activeThreadId, _myProcessId, false); //release the attachment
  10.             if (Clipboard.ContainsText())
  11.             {
  12.  
But it doesn't? Any ideas why as the correct windows get highlighted?
Your knowledge and experience will be greatly appreciated, cheers.
Feb 9 '10 #1

✓ answered by tlhintoq

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.

6 14305
tlhintoq
3,525 Expert 2GB
Don't try to do it through keystroke trickery. Just use the clipboard class and send what you want to the clipboard.
http://msdn.microsoft.com/en-us/libr...clipboard.aspx
Feb 9 '10 #2
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?
Feb 9 '10 #3
tlhintoq
3,525 Expert 2GB
"The other app" ?

So you're not trying to have your application send to the clipboard...
You're trying to programmatically 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.
Feb 9 '10 #4
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?
Feb 9 '10 #5
tlhintoq
3,525 Expert 2GB
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.
Feb 9 '10 #6
Cheers tlhintoq. Thanks for your help again.
Feb 9 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by CLarkou | last post: by
2 posts views Thread by ABinBoston | last post: by
5 posts views Thread by Wayne Gibson | last post: by
1 post views Thread by Logan McKinley | last post: by
5 posts views Thread by Daniel N. | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.