Filling Clipboard with SendKeys("^C")


I want to have something like that:

User selects some text in any application , hit the F8 key and I get this with the clipboard.

Everything is fine when using e.g. notepad.
But doing the same in Chrome, or Internetexplorer I did not get the selected text. I get the text selected before.
I absolutely did not see why this happens. Anyone who can help?

I use:

Dim oleo as new OLEObject(“WScript.Shell”)
Dim c as New Clipboard

It dosen’t work no matter if i use the global hotkey or put that in timer and manually put the focus to the browserwindow.



Looks as if Chrome taps directly into the keyboard for ^C. On the other hand ^A works just fine with SendKeys and Chrome.

Ok, it is late and perhaps i didn’t see it…

Someone who can tell me, why:


works perfekt…???


just another OLEObject :wink:

Ok, now I really give up.

I tested with this code:

[code]if a then
DIm oleo as new OLEObject(“WScript.Shell”)
Dim c as new Clipboard
dim ot as string = c.Text


dim c2 as New Clipboard


DIm oleo as new OLEObject("WScript.Shell")
Dim c as new Clipboard
'dim ot as string = c.Text


dim c2 as New Clipboard

end if

a = not a[/code]

Only the line: dim ot as string = c.Text differs. But in MOST Apps the if is not working but the else works. In Chrome both are working. I could reproduce that on two win 7, but I really don’t understand it.
Even having a look to the clipboard (with CTRL+V in notepad) shows me, that the selected text really wasn’t copied.
But why could a line like that (dim ot as string = c.Text) result in that?


Check this out:

This might help you.

Hi John,
don’t know how that could help with this problem… :wink:

[quote=264695:@John Hansen]Check this out:

This might help you.[/quote]

Make sure the default settings for Time1:
Timer1.mode = 0 // Off
Timer1.period = 100

[quote=264698:@Marius Dieter Noetzel]Hi John,
don’t know how that could help with this problem… ;)[/quote]

To get it to work, your window application need to be activated. When you run your “oleo.SendKeys(”^c")" in your application, you only copy what is selected in that current application, as that is the activated window, and not the browser.

I tried to use my application “Sendkeys” on Microsoft Internet explorer. And every time I set Microsoft Internet Explorer as the Active Window, the selected text was not highlighted any more. :(…

I mange to create a simple example. You need two timers and a TextArea for this example. When you press F8 the selected text from active window will be copied into TextArea1


  ' Timer1 default settings:
  ' Timer1.mode = timer.ModeMultiple
  ' Timer1.period = 500
  Dim wsh as new OLEObject("WScript.Shell")
  // Check if Function key F8 is pressed
  If Keyboard.AsynckeyDown(&h64) then    
    //Copy selected text from active window
  end if
  wsh = Nil


  // Timer2 default settings:
  // Timer2.mode = timer.ModeOff
  // Timer2.period = 200
  Dim clip As New Clipboard
  TextArea1.AppendText "Key F8 Pressed and following text from clipboard:  " + clip.text+ EndOfLine

Remember to set the default settings for Timer1 and Timer2 as mentioned in the code. You might have to change the time settings a little bit for your needs. This example does not exclude the previous text in Clipboard first time, you will need to add that code in your self.

Hi John!

Thank you for all the work. But that all is not the Problem. That all works, my only question is, why - If I put the dim ot as string = c.Text in - the complete function stops working.

In my case the active application is never my xojo app, because I work with a System global Hotkey.
But the same problem appears if I put it in a timerAction and set period to 5000 or so.
In this case I can start the timer with a button and bring some other app to the focus.
As I said, all that works.


Hmm. What happens if you add a delay “DelayMBS(0.30)” between dim ot as string = c.Text and oleo.SendKeys("^c")

dim ot as string = c.Text