Send CTRL+C to active Application

F

Frank Uray

Hi all

I know, this problem was discusted before,
but I am still not sure how it can be done ...

I need to get the currently selected Text from the
currently active application.
Right now, I just do "System.Windows.Forms.SendKeys.SendWait("^c")",
and this works in the most applications, but not in word ... :-((

How is the right way to do this ?
I just need to simulate CTRL + C to copy the selection into the Clipboard,
from any applications ???

Thanks for feedback !

Best regards
Frank Uray
 
P

Peter Duniho

[...]
Is there a way to send CTRL+C, so also Word would be working ...
When some text in word is selected and I press CTRL+C on the keayboard,
the selected text is in the Clipboard ... This is what I need to do in C#
... :))

I believe that Jeff answered that exact question.

More generally, there is no 100% reliable way to do what you want. If you
want to invest the time and effort for each application that doesn't
follow the simplest model and special-case those for your own utility, I'm
sure you can eventually get everything to work. But there's simply not
going to be a "one size fits all" solution.

Pete
 
F

Frank Uray

Hi Peter

Thanks for your answer.

You maybe right, but what I dont understand is:
When I press CTRL+C on the Keyboard all works fine ...
Why is it not possible to really simulate Keyboard press ??

Right now I am playing arround with SendMessage and WM_GETTEXT.
This should work also, do you know how to handle it ??

Thanks and best regards
Frank Uray


Peter Duniho said:
[...]
Is there a way to send CTRL+C, so also Word would be working ...
When some text in word is selected and I press CTRL+C on the keayboard,
the selected text is in the Clipboard ... This is what I need to do in C#
... :))

I believe that Jeff answered that exact question.

More generally, there is no 100% reliable way to do what you want. If you
want to invest the time and effort for each application that doesn't
follow the simplest model and special-case those for your own utility, I'm
sure you can eventually get everything to work. But there's simply not
going to be a "one size fits all" solution.

Pete
 
J

Jeff Gaines

You maybe right, but what I dont understand is:
When I press CTRL+C on the Keyboard all works fine ...
Why is it not possible to really simulate Keyboard press ??

Right now I am playing arround with SendMessage and WM_GETTEXT.
This should work also, do you know how to handle it ??

Can you show us how you are finding the correct window in Word, i.e. post
a sample of code showing how you get from the Word app to the document
window.
 
F

Frank Uray

Hi Jeff

Thanks again for your answer.

In the meantime I managed to do it like this:
SendMessage((IntPtr)GetActiveWindowHandle(), WM_COPY, (IntPtr)0, (IntPtr)0);

It just does not work for notepad, dont know why,
but there I just use SendKeys.SendWait("^c").

Best regards
Frank Uray
 
S

sha sha

control+ c not working in notepad
Hi all

I know, this problem was discusted before,
but I am still not sure how it can be done ...

I need to get the currently selected Text from the
currently active application.
Right now, I just do "System.Windows.Forms.SendKeys.SendWait("^c")",
and this works in the most applications, but not in word ... :-((

How is the right way to do this ?
I just need to simulate CTRL + C to copy the selection into the Clipboard,
from any applications ???

Thanks for feedback !

Best regards
Frank Uray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top