Re: How to remotely activate Ctrl-C ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jack (replyto_at_newsgroup)
Date: 03/29/04


Date: Sun, 28 Mar 2004 21:38:00 -0500

I run into some obstacle and I do not know how to solve that.
1. By trial I've found that my hotkey can be only Ctrl+(A-Z) --->except
some common Windows shortcuts like Ctrl+X, Ctrl+O etc.
    Selecting anything else causes virtual VK_CONTROL and VK_C not working
(Clipboard gets nothing)
2. The first attempt to get new clipboard content fails with Run-Time Eror
521: "Can't open Clipboard
There is not any other app using clipboard at that moment. It looks like my
own app prevents opening the clipboard again. I have noticed when using a
debugger that after repeating immediately the same line of code there is not
error any more as if that debugger acknowledgment of error clears the way to
open the clipboard again.
So, to avoid that error I coded the following way:

 On Error Resume Next
        lname = Clipboard.GetText
        lname = Clipboard.GetText 'specially doubled line to avoid run-time
error 521

This solves the immediate problem but I do not think it is a right approach
to it.

After more thinking and experimenting I came to the conclusion that the
error is caused by the fact that the keyboard keys are physically pressed
down (hotkey) at the moment when virtual keys are being called Up and that
KEYEVENTF_KEYUP may just not work. But I cannot prove it. I put some time
delay so I could give time to release keyboard keys before calling virtual
Ctrl+C but the error still was in there.
I am very much interested in your opinion about that error and solving it
another way.
Also, is it possible for me to use another hotkey key combination, or am I
stuck with Ctrl+(A-Z) only?
Thanks,
              Jack

"J French" <erewhon@nowhere.com> wrote in message
news:406723f4.26641964@news.btclick.com...
> On Sun, 28 Mar 2004 11:14:49 -0500, "Jack" <replyto@newsgroup> wrote:
>
> >Thanks a lot. I needed that.
> >I've completely forgot about keybd_event :)
> >But now, I have a problem when trying your code.
> >When executing:
> > Call keybd_event(VK_CONTROL, 0, 0, 0) ---> it returns from this call
> > Call keybd_event(VK_C, 0, 0, 0) -----> it never returns from this
call
> >I am using Windows 2000 and vbasic5 if that matters.
> >
> >My complete relevant code looks like that:
> >
> >Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal
> >wParam As Long, ByVal lParam As Long) As Long
>
> Christ ! Don't get the Hot Key like that !
> Doing things like that inside a Windows Hook is lethal
> - you need a bit of protection
>
> We both know that the routine works inside a VB Timer Event, so just
> Enable the Timer inside your WinHook
>
> >
> >Const WM_HOTKEY = &H312
> >
> >Select Case uMsg
> >
> > Case WM_HOTKEY
> > If oHotKey = 1 Then
> > Const VK_CONTROL = &H11
> > Const VK_C = &H43
> > Const KEYEVENTF_KEYUP = &H2
> > Debug.Print "Hotkey: " & wParam
> > Call keybd_event(VK_CONTROL, 0, 0, 0)
> > Call keybd_event(VK_C, 0, 0, 0) '-----------> never
> >returns from this call
> > Call keybd_event(VK_C, 0, KEYEVENTF_KEYUP, 0)
> > Call keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
> > Call ProcessClipboard
> > End If
> >End Select
> >error_WindowProc:
> > WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
> >End Function
>