How to trigger Paste in terminal server window?
-
Hi! I've asked a similar question some time ago, but unfortunately without usable results, so I try again. I put some text into the clipboard and want to trigger a paste action inside a terminal server session (i.e. programmatically do what happens when you press Ctrl+V inside a mstsc window). Yes, I know that you can't programmatically see the different windows inside the WTS session and that the currently active application will be the target for my paste, but that's exactly what I want. So far I tried using
SendKeys
, P/invoke toSendInput
andkeybd_event
, postingWM_PASTE
or evenWM_KEYDOWN
andWM_KEYUP
with the exact parameters Spy++ reports, but I can't get it to work. The first 4 ways simply give no visible result at all, with WM_KEYDOWN/UP I get a plain "v" instead of Ctrl+V. Does anyone have any further idea?Regards, mav -- Black holes are the places where God divided by 0...
-
Hi! I've asked a similar question some time ago, but unfortunately without usable results, so I try again. I put some text into the clipboard and want to trigger a paste action inside a terminal server session (i.e. programmatically do what happens when you press Ctrl+V inside a mstsc window). Yes, I know that you can't programmatically see the different windows inside the WTS session and that the currently active application will be the target for my paste, but that's exactly what I want. So far I tried using
SendKeys
, P/invoke toSendInput
andkeybd_event
, postingWM_PASTE
or evenWM_KEYDOWN
andWM_KEYUP
with the exact parameters Spy++ reports, but I can't get it to work. The first 4 ways simply give no visible result at all, with WM_KEYDOWN/UP I get a plain "v" instead of Ctrl+V. Does anyone have any further idea?Regards, mav -- Black holes are the places where God divided by 0...
mav.northwind wrote:
So far I tried using SendKeys,
Like this?
SendKeys.SendWait("[Clipboard content here]");
or like this:
// simulates a Ctrl+V keypress
SendKeys.SendWait("^a^v");If you've tried the second one, it wont work - as you probably have noticed. Console windows doesn't accept pasting of text. Try getting the content of the clipboard somehow, store it in a string and then write it out like this:
SendKeys.SendWait(clipboardContent);
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
-
mav.northwind wrote:
So far I tried using SendKeys,
Like this?
SendKeys.SendWait("[Clipboard content here]");
or like this:
// simulates a Ctrl+V keypress
SendKeys.SendWait("^a^v");If you've tried the second one, it wont work - as you probably have noticed. Console windows doesn't accept pasting of text. Try getting the content of the clipboard somehow, store it in a string and then write it out like this:
SendKeys.SendWait(clipboardContent);
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
Hi! First of all, thanks for you reply. Unfortunately, neither the first nor the second version has any visible effect on the mstsc window.
Regards, mav -- Black holes are the places where God divided by 0...
-
Hi! I've asked a similar question some time ago, but unfortunately without usable results, so I try again. I put some text into the clipboard and want to trigger a paste action inside a terminal server session (i.e. programmatically do what happens when you press Ctrl+V inside a mstsc window). Yes, I know that you can't programmatically see the different windows inside the WTS session and that the currently active application will be the target for my paste, but that's exactly what I want. So far I tried using
SendKeys
, P/invoke toSendInput
andkeybd_event
, postingWM_PASTE
or evenWM_KEYDOWN
andWM_KEYUP
with the exact parameters Spy++ reports, but I can't get it to work. The first 4 ways simply give no visible result at all, with WM_KEYDOWN/UP I get a plain "v" instead of Ctrl+V. Does anyone have any further idea?Regards, mav -- Black holes are the places where God divided by 0...
Why not do the following, where you know how to write a single char to the console (as indicated in your question where you said you can send a 'v' character):
if (Clipboard.ContainsText()) {
string ct = Clipboard.GetText();
foreach (char c in ct)
WriteCharToConsole(c);
}I know it is a hack, but it will work. Sorry for not getting back to you on your original post, but I got kind of sidetracked. I still plan to look into how to do this the "right" way, but this will suffice until then.
Sounds like somebody's got a case of the Mondays -Jeff
-
Why not do the following, where you know how to write a single char to the console (as indicated in your question where you said you can send a 'v' character):
if (Clipboard.ContainsText()) {
string ct = Clipboard.GetText();
foreach (char c in ct)
WriteCharToConsole(c);
}I know it is a hack, but it will work. Sorry for not getting back to you on your original post, but I got kind of sidetracked. I still plan to look into how to do this the "right" way, but this will suffice until then.
Sounds like somebody's got a case of the Mondays -Jeff
Thanks, Jeff.
Skippums wrote:
Sorry for not getting back to you on your original post,
No problem here - you're not obliged to solve my problems :) The main reason why this "hack" won't do, I'm afraid, is that the clipboard contains RTF... Nevertheless, thanks for the suggestion.
Regards, mav -- Black holes are the places where God divided by 0...
-
Thanks, Jeff.
Skippums wrote:
Sorry for not getting back to you on your original post,
No problem here - you're not obliged to solve my problems :) The main reason why this "hack" won't do, I'm afraid, is that the clipboard contains RTF... Nevertheless, thanks for the suggestion.
Regards, mav -- Black holes are the places where God divided by 0...
What if you read the RTF into the RichTextBox.Rtf property, then read it back out from the RichTextBox.Text property? This raises the hack level to about a 9 out of 10, but again, I think it may work for you. Also, isn't there a way to get RTF text from the clipboard without the formatting? You may want to check into that as well.
Sounds like somebody's got a case of the Mondays -Jeff
-
What if you read the RTF into the RichTextBox.Rtf property, then read it back out from the RichTextBox.Text property? This raises the hack level to about a 9 out of 10, but again, I think it may work for you. Also, isn't there a way to get RTF text from the clipboard without the formatting? You may want to check into that as well.
Sounds like somebody's got a case of the Mondays -Jeff
:) Sure, there are easy ways to retrieve plain text from RTF, but that's not the point. The requirement is to paste the contents of a RichTextBox into the terminal server session, just like one would with a local application. Formatting etc. has to be retained. What I cannot understand is that I don't get the same results when sending the same messages with the same parameters Spy++ is recording...
Regards, mav -- Black holes are the places where God divided by 0...
-
What if you read the RTF into the RichTextBox.Rtf property, then read it back out from the RichTextBox.Text property? This raises the hack level to about a 9 out of 10, but again, I think it may work for you. Also, isn't there a way to get RTF text from the clipboard without the formatting? You may want to check into that as well.
Sounds like somebody's got a case of the Mondays -Jeff
:-D Victory is mine! (as Stewie Griffin would say) Finally, I got some code from a guy in an MCE forum who was sending keystrokes to an mstsc window in response to IR remote control events. He also used
keybd_event
(which didn't work in my tests), but also usedAttachThreadInput
, so I think this was the missing piece. With this code I was able to send Ctrl+V to mstsc, thus triggering paste into the current application. Works like a charm! Anyway, thanks for your support!Regards, mav -- Black holes are the places where God divided by 0...