| re: Requested clipboard operation did not succeed
Wow - this just keeps getting wierder. I've simplified the problem
and it still makes no sense to me.
The problem is basically that Windows apps such as Notepad and
IExplorer (the only 2 I've tested with) seem to "hang on" to the
clipboard after a use keybd_event() to send a CTRL-C to that
application. But only if I've previously done a paste using CTRL-V.
I've eliminated my code to the the paste. I can now make the problem
come and go just by pressing CTRL-V on the keyboard myself. If I
don't paste, my code that sends the CTRL-C using keybd_event() works
every time. If I paste text into notepad (either by pressing CTRL-V
myself, or using keybd_event() to do it) then after issuing a CTRL-C
using keybd_event() the clipboard stays locked by notepad for several
seconds before I can access it.
What's odd is if I eliminate my keybd_event() CTRL-C code and just
manually press the CTRL-C and CTRL-V when needed - all works fine. My
program can read the clipboard and write the clipboard with zero
delays.
So this suggests it's in my "copy" code. But my "copy" code is about
as simple as it can get. Here it is...
keybd_event(0x11, (byte)NativeWIN32.MapVirtualKey(0x11,0), 0,
(IntPtr)0); //...CTRL key down
keybd_event(0x43, (byte)NativeWIN32.MapVirtualKey(0x43, 0), 0,
(IntPtr)0); //...C key down
keybd_event(0x43, (byte)NativeWIN32.MapVirtualKey(0x43, 0), 0x02,
(IntPtr)0); //...C key up
keybd_event(0x11, (byte)NativeWIN32.MapVirtualKey(0x11, 0), 0x02,
(IntPtr)0); //...CTRL key up
string strClip = Clipboard.GetText(); //<<<THROWS EXCEPTION IF I"VE
PREVSIOUSLY DONE A PASTE
That's it. I've tried putting Sleep()'s betwee the copy and my
GetText(). I've tried clearing the clipboard before doing the CTRL-
C. I've tried using SendInput() instead of keybd_event(). The ONLY
thing I've found that has an effect is to comment out my keybd_event()
lines and manually pressing CTRL-C before pressing the hotkey that
invokes this code. That works EVERY TIME NO PROBLEM.
So what the hell is the difference between me pressing CTRL-C on the
keyboard, and using keybd_event() as above??
-Bill |