Re: How to remotely activate Ctrl-C ?
From: J French (erewhon_at_nowhere.com)
Date: 03/29/04
- Next message: Martin: "Object Persistance"
- Previous message: Ayaz Ahmed: "Re: How do you tell if a folder exists"
- In reply to: Jack: "Re: How to remotely activate Ctrl-C ?"
- Next in thread: Jack: "Re: How to remotely activate Ctrl-C ?"
- Reply: Jack: "Re: How to remotely activate Ctrl-C ?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 29 Mar 2004 11:35:51 +0000 (UTC)
I've been testing things while writing this, it is more a log of my
findings - but should, I hope be useful.
On Sun, 28 Mar 2004 21:38:00 -0500, "Jack" <replyto@newsgroup> wrote:
>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)
I've looked at that, and you are right, as you later guess, because
those other keys like Alt are still 'down'
- so the App is getting Ctl Alt C
You could try sending it a Key Up for the Alt or Shift Key
Alt is VK_MENU is &h12
VK_SHIFT is &h10
>2. The first attempt to get new clipboard content fails with Run-Time Eror
>521: "Can't open Clipboard
When you start your App, try Clipboard.Clear
>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.
It looks ugly, but I guess we are meddling with stuff that confuses
Windows
>
>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 think you are absolutely right
Have you tried forcing in a Key Up for the Alt ?
- no - I just tried it - no dice - Alt activates the menu
I have got it working reliably with Ctl Z
- Ctl F over the VB IDE gave me ureliable results
... until I put this after the Keybd_Events
' --- Give up Timer Slice
DoEvents
Sleep 250
That kind of figures - one needs to give the other App a chance to do
its stuff before grabbing the Clipboard data
I also have it working with Ctl + vbKeyF12
>I am very much interested in your opinion about that error and solving it
>another way.
Have you looked at the SetClipboardViewer API ?
The www.AllAPI.net Guide has a good example
- that way you can leach off Ctl C
>Also, is it possible for me to use another hotkey key combination, or am I
>stuck with Ctrl+(A-Z) only?
I think the only unsafe keys are the Alt ones
- because the Alt activates the other App's Menu, which makes things
unreliable
- I also tried Ctl F1 - not a widely used combination - no problem
Amusingly hijacking F1 works fine as well
- nobody using your utility would want the Help to pop up
I did not have any Clipboard errors, but I did find it slightly
unreliable until I put in the : DoEvents and Sleep 250
I'm not entirely sure what you are aiming for, and the choice of
solution depends on your objectives.
However, I'm pretty sure that you can make something that does what
you want using one of these approaches.
I'll keep an eye on this thread - it's very interesting
- Next message: Martin: "Object Persistance"
- Previous message: Ayaz Ahmed: "Re: How do you tell if a folder exists"
- In reply to: Jack: "Re: How to remotely activate Ctrl-C ?"
- Next in thread: Jack: "Re: How to remotely activate Ctrl-C ?"
- Reply: Jack: "Re: How to remotely activate Ctrl-C ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|