[RESOLVED] How can I Run "Copy" Command/Function Outside of Program/Form?

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] How can I Run "Copy" Command/Function Outside of Program/Form?

Looking for a way, to run, the equivalent of "Ctrl+C" using my own VB program. Essentially the reason I am doing this is because the program I am trying to write is a converter, and the plan is to have it use "Ctrl+F" instead of "Ctrl+C". It would copy whatever is highlighted, check if it is a number if it is convert it to another number and paste it back to where it was copied from.

I will figure the rest out later, for now I am just looking for a way to copy selected text using a pre-specified shortcut key combination such as "Ctrl+F" from any window in any program. Heck it can even store the copied text in the regular clipboard, I just don't want to use Ctrl+C to do the copying.

If I need to explain better please say so, and as always any help, suggestions ideas, links etc is very much appreciated.

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

Perhaps I should not have chosen "Ctrl+F" as my keyboard combo. Let us use"ctrl+Q" instead. (That way there is no confusion to the 'Find" feature Ctrl+F usually does)

So I need to select some text somewhere on a random window in a random program, and hit Ctrl+Q, once hit it will copy the selected text into the clipboard, convert it (using a math equation I'll input later, and re-paste the new converted value exactly where it was originally converted from.

You thik setting focus on the third party window still applys in the same way?

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

To be honest, what you're asking for is a global keyboard hook. I'm not sure VB is the best language for this. I'm not saying VB can't do it, but it's likely to be outside the bounds of what the .NET framework can do. It's going to be deeper at a lower level. I'd think that C/C++ would be a much better candidate.

I got the majority of this off of somewhere I forget where, but it isn't my original code just for disclaimer purposes. It will recognize that I have hit a keyboard combo even outside the program, but it wont run the copy function.

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

dday - I think you're missing the point... he's not trying SEND Ctrl+F ... he wants to use Ctrl+F (or Q, or Z, or T, or what ever) FROM ANY application... as a global hotkey. So let's say he has Word open, selects some text, presses Ctrl+Q ... it should find the selected text, copy it to the clipboard, process it, then paste the new value right back into the same spot.

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

Ohhh.... Yeah I did misunderstand that. I was under the assumption that he wanted to find text on a 3rd party application and copy the text if anything was found. I don't know how that could even be done... I'll have to bow out of this one.

That's all of the code, including the copy and paste functionality and the hot-key functionality. Just in case anyone else ever comes across this. Now there may be a better way to accomplish this but this is what I came up with.

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

I wouldn't involve the clipboard or use sendkeys if I didn't have to. This is my idea, Register the hotkey, when hotkey is detected get handle of the foreground app, with that we get the handle of the control that has focus on the app. I'm not sure how you check if a control is an edit control so I just check to see if its classname has the word "edit" in it. , I then take the external text & convert to a decimal, add 1.1 to it and send it back to the control as a string...

Re: How can I Run "Copy" Command/Function Outside of Program/Form?

I'm looking at what you have supplied and it makes sense code wise, but I am unsure of why I would do that? Any chance you can clear up why it'd be better to do it that way?

Just that I've seen problems with the clipboard when attempting to read and write to it too often or too fast, so I'm wary to use it like that, plus I don't like the idea of apps overwriting whatever I currently have stored on the clipboard.