Question sendkeys - alt tab & copy -> works in one application, but not in the other?

mmy

Member
Joined
Oct 5, 2007
Messages
24
Programming Experience
1-3
Hi,
I have created 2 projects, both sending alt tab + copy when I press a button.
The objective is to copy the selected text in another random application.
VB.NET:
txtInfo.Focus()               'I have to do this, otherwise this code never works
Clipboard.Clear()
Application.DoEvents()
SendKeys.SendWait("%{TAB}")     'send alt tab to switch from the screen
Application.DoEvents()
SendKeys.SendWait("^c")            'send copy function (if that one is ctrl c)
Application.DoEvents()
MessageBox.Show(Clipboard.GetText)

In the first project, with only one button and this code, the function seems to work everytime. When I click the button, it sends alt tab (so changing the active screen to the application with the selected text), sends ctrl c and shows the content of the clipboard in a messagebox.

In the other project however, this codes not always works. Somethimes it does the copy fine, other times you have to press 2 or 3 times. When I place the code in a do while - loop and say it has to stay in this loop until there is something in the clipboard you can see the screen doing alt tab a lot before stopping.

This project also contains other buttons, different layout, ... But none of them are addressed when calling this fuction.

Anybody knows what this problem could be?
And even better, anybody knows a different way to do the copy function of the selected text, since this method doens't look so stable... It seems like the processor runs the code too fast to perform the copy function correct...
 
Back
Top