From: mayayana on
What you want to do is very complex and
may not be possible. Presumably you want
to find the foreground window to get the
last selection. With Active Accessibility you
could track changes in focus and use that to
get the foreground window. Then maybe you'd
get the selection from the last window that
was in the foreground? Already it's getting
awkward.

Assuming that you can get the window you want,
then you're faced with a different scenario for each
program.

Word has an object model.

For IE you want
to get the document.selection IF the document.
selection.type is "Text". So you need to get hold of
the IE document probably by enumerating
child windows until you find an Internet Explorer_Server
class window that you can retrieve a Document object
from. You *could* do that, but what if the person is
using Firefox?

For Notepad you might
be able to use EM_GETSEL along with API to get
window text. I'm not sure about that. But even if it
works that's only for a standard edit control.

EM_GETSELTEXT is only for a RichEdit and probably
won't work for a foreign process. Functions that return
a pointer won't return a valid pointer to an external
process because the pointer is a relative address.

Etc.

There's nothing that says
a program must make it's text or selection available.
Even Active Accessibility has limits as to what it can
return from different types of windows, and as far as
I know there's no AA method to return the current
selection -- only the text content.

And even if you work all that out, how do you figure out
what the last selection's parent program is? Will you
create a reference list of unique window class names
and then just drill down until you find one? .... Then
decide from there how to get the selection? So you'd
retrieve the document object if you come across an
"Internet Explorer_Server" class window, or drill down to
the edit window when you find a "Notepad" class window,
etc.? With that method you'll be severely limited in
terms of how many program types you can deal with.
You'll get IE but not Firefox or Opera; MS Word but not
OpenOffice Writer, Abiword, WordPro, etc.

Maybe someone will come up with a way to do what
you want. Maybe there's some kind of high-level
functionality that I'm not thinking of. But I'd be surprised
if that's the case. It sounds like you're trying to
just send key sequences to get the different windows,
but I don't see how that can work. You can't just usurp
the Desktop and set focus to whatever window you like.

> >>> ALT+TAB
> > Next instruction was send CTR+INS :).
>
> Next :
> ALT +TAB+SHIFT
>
> and I must read the text like SHIFT+INS.
> How can I read text to any variable?
>
>
>


From: ptpwjp on
> What you want to do is very complex and
> may not be possible. Presumably you want
> to find the foreground window to get the
> last selection.
Yes.

......
> Word has an object model.
>
> For IE you want
> to get the document.selection ...... but what if the person is
> using Firefox?
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?

> And even if you work all that out,
I don't understand this, I'm not English.

> how do you figure out
> what the last selection's parent program is?
It isn't interesting for me what parent program is.
I need only selected text.

In old times, sometimes, in newspapers there was same programs which added
new menu to system menu. For example: "change to yellow", near menu copy,
past, cut, delete. But it was always difficult to uninstall, and I don't
like this kind of changes. But the sense of problem is the same.


......
> Maybe someone will come up with a way to do what
> you want. Maybe there's some kind of high-level
> functionality that I'm not thinking of. But I'd be surprised
> if that's the case.

> It sounds like you're trying to
> just send key sequences to get the different windows,
> but I don't see how that can work. You can't just usurp
> the Desktop and set focus to whatever window you like.



From: mayayana on
MS newsgroups seem to be acting up again
and blocking my post. See here:

http://www.google.com/url?url=http://groups.google.com/g/8357ff0a/t/c20f2985
43cfa7f3/d/1bf2a29ad8f3353b%3Fq%3Dkeybd_event%2Bhook%231bf2a29ad8f3353b&ei=b
dTtSrHnIubWlAew6tHwCg&sa=t&ct=res&cd=1&source=groups&usg=AFQjCNECZknGAyvGZjM
vLAOecZD7-7hUVQ




From: ptpwjp on
> 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?




From: mayayana on
> >
> > 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.

> 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.