Connect with Expertise | Find Experts, Get Answers, Share Insights

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

DOSrelic's Avatar  
Join Date: Sep 2006
Location: Waipukurau New Zealand
Posts: 13
#1: Feb 9 '10
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.
best answer - posted 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.

tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#2: Feb 9 '10

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


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
DOSrelic's Avatar  
Join Date: Sep 2006
Location: Waipukurau New Zealand
Posts: 13
#3: Feb 9 '10

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


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?
tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#4: Feb 9 '10

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


"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.
DOSrelic's Avatar  
Join Date: Sep 2006
Location: Waipukurau New Zealand
Posts: 13
#5: Feb 9 '10

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


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?
tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#6: Feb 9 '10

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


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.
DOSrelic's Avatar  
Join Date: Sep 2006
Location: Waipukurau New Zealand
Posts: 13
#7: Feb 9 '10

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


Cheers tlhintoq. Thanks for your help again.
Reply

Tags
sendkeys.send format