Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, June 21, 2012 6:25 PM
I am trying to set clipboard data and invoke a paste to windows. My data is successfully set into the clipboard but when I perform a
SendKeys.Send("^V");
with an image in the clipboard, it does not paste the image. When text is in the clipboard, it does successfully paste the text.
When I set the clipboard content to contain an image and then close my application and manually perform a CTRL+V, the image pastes successfully.
Does anyone have any idea what I am doing wrong? Is there another way to invoke a paste?
Many Thanks
Rod
All replies (5)
Saturday, June 23, 2012 8:56 AM âś…Answered | 1 vote
I just made a nice massive long reply and I have just discovered that I am sending an Upper case V and I need to send a lower case one!!!
Now I feel stupid!
Many Thanks for your input all, appreciated.
For anyone else that has this issue do:
SendKeys.Send("^v");
AND NOT:
SendKeys.Send("^V");
lol.
Thursday, June 21, 2012 8:25 PM
SendKeys is flaky. Make sure you have read the documentation on SendKeys, since it lists a few limitations. There are a few other ways to do this, depending on the application, but really they are all hacky. Here are a few I can think of:
1. Use windows messages to send the keys. This gives you lower level keyboard control, but is difficult if you are not familiar with the windows API. You will need to P/Invoke FindWindow and SendMessage.
2. Assuming the application has an Edit - Paste menu, you could use FindWindow and SendMessage to send the WM_COMMAND for the menu item. This is much more likely to be successful than option 1, but more complex. You would need to use Spy++ to find the appropriate message to send. How to do this is probably beyond the scope of a simple forum question. :-(
3. If this is a Microsoft Office application, there are COM APIs for communicating with it and that is a much better approach.
4. If the application supports DDE you might try that. You would need to talk to the software vendor or read their documentation to find out.
Overall, trying to get another application to automatically do something when it is only expecting user input and isn't designed to be directly controlled, tends to be unreliable. :-(
Friday, June 22, 2012 6:19 PM
Thanks for your input Moby, helpful but options 3 & 4 are not possible and I think options 1 & 2 rely on knowing which application I need to send a paste to? I wasn't specific but I want the paste to go to whatever windows application is in the foreground. I can get the current foreground app but I am assuming that the message to send paste is going to differ from application to application? Hence why I simply wanted to perform a CTRL+V and let windows take care of it.
I am going to spend some more time on this tomorrow, I'm sure I'll come up with a workaround! Will update here when I figure it out.
Thanks
Friday, June 22, 2012 7:55 PM
Your not showing any code, so I just guessing, the current foreground app must first obtain focus/active
"Rod Hall" wrote in message news:07536229-c872-4e43-a0ef-4b5b703c4d5e@communitybridge.codeplex.com...
I am trying to set clipboard data and invoke a paste to windows. My data is successfully set into the clipboard but when I perform a
SendKeys.Send("^V");
with an image in the clipboard, it does not paste the image. When text is in the clipboard, it does successfully paste the text.
When I set the clipboard content to contain an image and then close my application and manually perform a CTRL+V, the image pastes successfully.
Does anyone have any idea what I am doing wrong? Is there another way to invoke a paste?
Many Thanks
Rod
Friday, February 6, 2015 4:34 PM
You got that right :). One time it works good for me the next time it doesn't. I made a quick "One Click" screen capture and paste to MS Word.
' One Click Print Screen To Word
Set objShell = WScript.CreateObject("WScript.Shell")
Set objWordApp = CreateObject("Word.Application")
Set WshShell = CreateObject("Word.Basic")
WshShell.SendKeys "{prtsc}"
objWordApp.Visible = True
objWordApp.Documents.Add
objWordApp.Selection.Paste
Set objShell = Nothing
Set objWordApp = Nothing
Set WshShell = Nothing
Helpful nice guy