| |
 |
|
| .NET DotNet Forum Index » VB.NET Forum (Visual Basic .NET) » How can I read selected text in another application,... |
|
Page 2 of 2 Goto page Previous 1, 2 |
|
| Author |
Message |
| mayayana... |
Posted: Sun Nov 01, 2009 1:22 pm |
|
|
|
Guest
|
I'm afraid my post is not getting through to
the MS servers, though it may be getting
through to Google groups. (there's been a lot
of trouble that way lately.)
Here's another try:
Quote: It is reason why I send ctrl+ins , it is universal method I think.
But I can't get data to variable in my program. Haw can I do it?
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
It seems to work to get the current selection in
the active window. I can then just retrieve the
clipboard text. I'm running on Win98SE so I don't
know whether there might be security issues on
later systems with automated keystrokes.
Also, if they click a button in your program window
then of course they've changed the active window.
Even if you track changes in the active window, if
you want to catch the selection with keystrokes
then you will always be too late. Once you are
informed of the focus change you can no longer use
keystrokes.
Have you thought of trying a systemwide keyboard
hook? I'm not sure if this would work, but what I'm
thinking is something like the following:
- You set a keyboard hook.
- The person using your program uses a unique key
combination when they want to select current text.
- Your hook watches for that combination and when
it arrives you use the keybd_event method to capture
the current selection.
I don't know the specifics of how to do that in .Net.
Maybe someone else can provide that. And you'll
probably need to write a C++ DLL -- or obtain one --
to get your keyboard hook. |
|
|
| Back to top |
|
|
|
| mayayana... |
Posted: Sun Nov 01, 2009 1:39 pm |
|
|
|
Guest
|
|
| Back to top |
|
|
|
| ptpwjp... |
Posted: Sun Nov 01, 2009 2:45 pm |
|
|
|
Guest
|
Quote: 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? |
|
|
| Back to top |
|
|
|
| mayayana... |
Posted: Sun Nov 01, 2009 3:19 pm |
|
|
|
Guest
|
Quote:
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.
It's the API version of SendKeys.
Quote: 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?
Quote: 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. |
|
|
| Back to top |
|
|
|
| mayayana... |
Posted: Sun Nov 01, 2009 6:07 pm |
|
|
|
Guest
|
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. |
|
|
| Back to top |
|
|
|
| Nobody... |
Posted: Sun Nov 01, 2009 8:14 pm |
|
|
|
Guest
|
"ptpwjp" <ptpwjp at (no spam) op.pl> wrote in message news:hckoil$k5n$1 at (no spam) news.onet.pl...
Quote: 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. |
|
|
| Back to top |
|
|
|
| ptpwjp... |
Posted: Wed Nov 04, 2009 4:28 pm |
|
|
|
Guest
|
Quote: 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.
I test it today outside of the debugger, it work. |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Mon Nov 23, 2009 1:36 pm
|
|