How can I read selected text in another application, by vb program?

P

ptpwjp

That's interesting. I didn't know about that.
I just tried the API keybd_event, sending the
following parameters in succession:

17, 0, 0, 0
45, 0, 0, 0
45, 0, KEYEVENTF_KEYUP, 0
17, 0, KEYEVENTF_KEYUP, 0
I don't understand this table , but I tested it too.

In my program is instruction:
SendKeys.Send("%{TAB}^{INS}%+{TAB}")
(% - SHIFT; ^-CTRL; %- ALT)
1. %{TAB} - give processor to last application;
but chars: ^{INS}%+{TAB}"
are in keyboard , so they work:
2. ^{INS} copy selected text to box(?)- where- I haven't word in my mind
now,write it to me;
3. %+{TAB} - give processor to previous application;
But in my test, previous application wasn't my application, but VB2008 with
debugger,
so
after test was result:
the selected text was in box(?)- I test it in notepad,but processor was
returned to vb2008 but next instruction wasn't done.

So solution:
SendKeys.Send("%{TAB}")
SendKeys.Send("^{INS}")
SendKeys.Send("%+{TAB}")
isn't good.
Because after 1, the next can't be done, because in keyboard buffer there
wasn't anything.

So how can I get text from box to my variable in my VB2008 application?
 
M

mayayana

I don't understand this table , but I tested it too.

It's the API version of SendKeys.
2. ^{INS} copy selected text to box(?)- where- I
haven't word in my mind
now,write it to me;

You mean the Clipboard? The Clipboard is where
Ctrl+Insert sends the selected text. You realize
that you need to get the text from the Clipboard
after you do Ctrl+Insert?
So how can I get text from box to my variable in my VB2008 application?

Sorry but I didn't really understand the rest of
your post, except that I understood the Sendkeys
isn't working the way you want it to. It sounds
like you need to try it outside of the debugger. (?)
A .Net expert would have to advise you on that.

I think a system keyboard hook would really be
the way to go, but if you are new at this then that
might be too complex.
 
M

mayayana

I tried your approach and it does act very
strangely. The focus does not act as
expected. But then I tried a system keyboard
hook and chose a random combination:
ALT+CTRL+A

In the hook function I watched for that
combination and then sent CTRL+INS
and copied the clipboard text. It seems
to work fine. Using that method you would
just have people start your program, your
program would set the hook, then the
person would type your specified combination
(like ALT+CTRL+A) instead of pushing a
button in your program.

If you are not familiar with
keyboard hooks you can look that up. You
should be able to find a small, free keyboard
hook DLL that you can use to report all
keyboard input to any hWnd in your program.

The only catch is that you need to trap errors
because sometimes with the focus changing
the clipboard is momentarily locked.
 
N

Nobody

ptpwjp said:
In my program is instruction:
SendKeys.Send("%{TAB}^{INS}%+{TAB}")

It's preferable to send WM_COPY than trying to send Ctrl+C, or Shift+Insert
keys. This copies the text to the clipboard, but you need to specify the
correct window handle.

Also, what do you want to do once you have the text? There are free
dictionary tools that lets you select text in any program or web page, then
right click to get translation. This is a complicated task, even if you
already know how to use VB, and in many cases require you that you make
unmanaged standard DLL in C++, then use it in VB. I have done something
close, but it was not easy.
 
P

ptpwjp

You mean the Clipboard? The Clipboard is where
Ctrl+Insert sends the selected text. You realize
that you need to get the text from the Clipboard
after you do Ctrl+Insert?
In my language it is something like box, or casket,
in dictionary English - my language "clip" it is small wire
using to have a lot of pages together.
But I think it is it.

I understood the Sendkeys
isn't working the way you want it to.
No , Sendkeys work very good. But it isn't enough to me.


It sounds
like you need to try it outside of the debugger. (?)
Yes, yesterday was Sunday , and I haven't time to test it outside debugger.
Today I will test it more.
But test isn't enough for me, because I can't get text from box (clipboard?)
to variable in my application.
 
P

ptpwjp

It's preferable to send WM_COPY than trying to send Ctrl+C, or
Shift+Insert keys. This copies the text to the clipboard, but you need to
specify the correct window handle.
I will test it, I don't use clipboard object yet,
I think if I start use it I will be home.
Also, what do you want to do once you have the text? There are free
dictionary tools that lets you select text in any program or web page,
then right click to get translation.
No, I don't want translate it. I want to transform it.
 
P

ptpwjp

U¿ytkownik "mayayana said:
I tried your approach and it does act very
strangely. The focus does not act as
expected. But then I tried a system keyboard
hook and chose a random combination:
ALT+CTRL+A

In the hook function I watched for that
combination and then sent CTRL+INS
and copied the clipboard text. It seems
to work fine. Using that method you would
just have people start your program, your
program would set the hook, then the
person would type your specified combination
(like ALT+CTRL+A) instead of pushing a
button in your program.
It is a future of cause.
 
M

mayayana

I will test it, I don't use clipboard object yet,
I think if I start use it I will be home.

WM_COPY has the same limitation as WM_GETSEL.
It's for edit controls. I doubt that it will work for
browsers, MS Word, etc. That was the point I was
trying to make clear yesterday. If you want the
selection in any window then you are dealing with
many diffferent window types. Ctrl+Ins seems
to work, but I don't think there is a Windows message
for that.

(I just tried a test with Spy++. If I use Ctrl+Ins
with Notepad it sends WM_GETSEL. But when I
tried the same thing with text selected in K-Meleon
there was no message at all. Ctrl+Ins seems to be
somehow built into the system.)
 
M

mayayana

You realize
In my language it is something like box, or casket,
in dictionary English - my language "clip" it is small wire
using to have a lot of pages together.

That is the same in English -- a paper
clip. A clipboard is a hard board with a
type of clip attached. The clip has a spring
to hold papers tight against the board. It is
the thing that you see inspectors carry in the
movies when they inspect a power plant
or factory. :)
 
P

ptpwjp

That is the same in English -- a paper
clip. A clipboard is a hard board with a
type of clip attached. The clip has a spring
to hold papers tight against the board. It is
the thing that you see inspectors carry in the
movies when they inspect a power plant
or factory. :)
To small paper is glue no clip.
 
P

ptpwjp

It sounds
Yes, yesterday was Sunday , and I haven't time to test it outside
debugger.
Today I will test it more.

I test it today outside of the debugger, it work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top