Link to home
Start Free TrialLog in
Avatar of keron
keron

asked on

How to get the current Mouse Pos's text???

I want to get the current Mouse Position
's text.
How can I do it??

I also hear of that it's some difference
bettween IE's Text grab and Normal text grab.

Can someone give me a sample??
:)

Thanks!!!
God bless you
:P
Avatar of kretzschmar
kretzschmar
Flag of Germany image

? what exactly does you mean ?
- the caretpos in the text
- the caretpos in sreen-coords
- the letter under the mousecursor
- the mousecursorpos relativ to textcontrol
Avatar of Lischke
Lischke

Keron, what you wanna do is extremly difficult. It requires some very low level programming steps. I have done this last September for our on-click dictionary and had a real hard time. If you only need the text from an edit control then it is somewhat easier but for labels and other static text (button captions etc.) you have to go the hard way...

Ciao, Mike
Avatar of keron

ASKER

:)
I means
- the letter under the mousecursor
when the mouse on a text,you can get it!

the text maybe in other runningprogram;
Avatar of keron

ASKER

yeah

Lischke

something like on-click dictionary

You had done it?
can you give a sample???

thanks a lot!
One cannot give a sample for this as it involves about 3000 lines of code which depends heavily on each other. But I can give you the raw direction.

- install a global mouse hook
- on activation it is mapped into the process for which the mouse message is meant and you can redirect all text out function (WinNT) or directly hook the GDI (16 bit only, Win9x only )
- you need to make the particular window to draw its text again and wait until the text is through your hooks (e.g. using RedrawWindow(..))
- after this you need to setup the results and send it to your application (memory mapped files or pipes)

Further information:
- Detours library: http://research.microsoft.com/sn/detours (WinNT only)
- SetDDIHook (MSDN) (for Win9x only)


Ciao, Mike
Or an easier way:

Add a TTimer to a form.
In OnTimer event call GetCursorPos.
Now call WindowFromPoint.

That will give you a window handle.

Now send a WM_GETTEXT message.

I guess that would work for edit boxes and the like under the cursor, but for the view area in IE you'll need some other approach.

Cheers,
Phil.
I'm using Babylon Translator on my machine and it doesn't use Mike's approach, but instead it makes a snapshot of the area under the cursor and then does something like OCR on that bitmap.

Regards, Madshi.
Avatar of keron

ASKER

Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
Avatar of keron

ASKER

Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
Phil, your suggestion is obviously only working for text of windows and in case they have a caption only this one is returned. Try it e.g. with notepad's text. This does not work.

Madshi, are you really sure they use OCR? How do you came to this conclusion? To do a quick test write a little program with one form on which one label is placed. Set the label's caption to some arbitrary text and then set its font height to -3. Then run the program and try Babylon again. Does it still recognize the text (I assume it does with normal sized text)? If yes then forget about OCR.

To be honest, I don't believe at all that they use OCR as there can be too many different font styles and sizes. It would simply be to unreliable.


Ciao, Mike
Mike, it works even on bitmaps. I've just now tried it on the "Experts wanted - are you ready" bitmap in the top left corner of this html page (and Babylon found "ready"). You're right, it's a bit unreliable, sometimes Babylon gets some characters wrong. But it works unbelievable well!

www.babylon.com

Regards, Madshi.
Working on bitmaps is no criterion. The solution I wrote works even if you draw text on a bitmap and blit this bitmap on another bitmap and rotate this bitmap and put it on the screen. No OCR, believe me :-)

Ciao, Mike
Madshi I have to correct myself. It MIGHT be OCR (still not sure) but is definitely also not a similar technique I use. I downloaded the demo and (despite that it crashed after a few recognizion tasks) it was very unreliable. Simply setting a label font style to italic prevented Babylon from successfull recognition.

Ciao, Mike
If it works on a jpg (or gif) bitmap that was downloaded from the internet, it CANNOT be anything else, but only OCR.

Well, I had almost no crashes yet, but yes, italic is a problem for Babylon...   :-(
if Babylon5 crashes some people are in trouble  hehehe...
ASKER CERTIFIED SOLUTION
Avatar of scirocco1
scirocco1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial