• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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
0
keron
Asked:
keron
  • 5
  • 4
  • 3
  • +4
1 Solution
 
kretzschmarCommented:
? 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
0
 
LischkeCommented:
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
0
 
keronAuthor Commented:
:)
I means
- the letter under the mousecursor
when the mouse on a text,you can get it!

the text maybe in other runningprogram;
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
keronAuthor Commented:
yeah

Lischke

something like on-click dictionary

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

thanks a lot!
0
 
LischkeCommented:
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
0
 
philipleighsCommented:
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.
0
 
MadshiCommented:
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.
0
 
keronAuthor Commented:
Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
0
 
keronAuthor Commented:
Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
0
 
LischkeCommented:
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
0
 
MadshiCommented:
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.
0
 
LischkeCommented:
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
0
 
LischkeCommented:
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
0
 
MadshiCommented:
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...   :-(
0
 
intheCommented:
if Babylon5 crashes some people are in trouble  hehehe...
0
 
scirocco1Commented:
May be this little code can help you.
Use this code on a form.

// Code for Distance between two points.
funcTion Distancia(Pt1 : TPoint; Pt2 : TPoint) : Double;
var
  dx : LongInt;
  dy : LongInt;
begin
  dx:= pt1.x - pt2.x;
  dy:= pt1.y - pt2.y;
  Result := Sqrt((Dx * Dx) + (Dy * Dy));
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift:TShiftState; X,  Y: Integer);
var
  Pt1 : TPoint;
  Pt2 : TPoint;
  Dist : Double;
begin
  Pt1.x :=  Form1.Width div 2;
  Pt1.y  :=  Form1.Height div 2;
  Pt2.x := x;
  Pt2.y := y;
  Dist := Distancia(Pt1, Pt2);
  Form1.Caption := IntToStr(Pt2.x - Pt1.x)+#32+IntToStr(Pt1.y - Pt2.y)+' = '+
                   FloatToStr(Dist);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Form1.Canvas.MoveTo(Form1.Width div 2,0);
  Form1.Canvas.LineTo(Form1.Width div 2,Form1.Height);
  Form1.Canvas.MoveTo(0,Form1.Height div 2);
  Form1.Canvas.LineTo(Form1.Width,Form1.Height div 2);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Invalidate;
end;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 5
  • 4
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now