Solved

get text(word) at mouse cursor from any program

Posted on 2003-11-04
8
393 Views
Last Modified: 2010-04-05
Question: how to get text (just simple word) where the mouse cursor is, if it is possible?

For example the user moves mouse cursor anywhere in any windows application, presses some keys combination (shift+ctrl+a or other), then my application must get text at the mouse cursor. I need this to do a translation of that text or word, and possible to show a hint for that text o displaying translated message in some window on top.

I know that there is such possibility. But I don't know where to start from. If it is too complicated  plesase give some ideas where to start from. Thanks.

Marko
0
Comment
Question by:MarkoB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 9678848
only method i can think of is some form of OCR reader of the screen...
and that isn't very simple to do...

never done it, don't know how to do it either...but theoretically it could work.

Regards
//raidos
0
 

Author Comment

by:MarkoB
ID: 9678980
If it is so difficult, maybe to limit the task, is to get the text from Microsoft native applications, in text editing (viewing) control: Word, Internet Explorer, WordPad.
It should be a way to get text at mouse cursor, I think.

I've seen such implementation in MacMillian English dictionary.
0
 
LVL 1

Accepted Solution

by:
rvicentiu earned 250 total points
ID: 9679695
there are a few ways to do it,  here's the easy way :)
this should work for anything (except some listboxes without LBS_HASSTRINGS defined)
to test this make sure the mouse is where it should be before calling the function

var text: PChar;
    hWnd: dword;
    point: tpoint;
begin
  text:=stralloc(1000);
  GetCursorPos(point);
  hwnd:=WindowFromPoint(point);
  SendMessage(hwnd, WM_GETTEXT, 1000, DWORD(@text[0]));
  if length(text)=0 then begin
    Windows.ScreenToClient(hwnd, point);
    SendMessage(hwnd, LB_GETTEXT, SendMessage(hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(point.X, point.Y)), DWORD(@text[0]));
  end;
  strdispose(text);
end;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:rvicentiu
ID: 9679761
oh, in case you haven't figured this out yet the maximum length of the text in my example is 1000
use WM_GETTEXTLENGTH and LB_GETTEXTLEN to get the length of the text and allocate the buffer before getting the text
in a rich edit control, if the text to be copied exceeds 64K, use either the message EM_STREAMOUT or EM_GETSELTEXT
see Win32 help for more info
0
 

Author Comment

by:MarkoB
ID: 9684756
Thanks rvicentiu,
I'll try this code soon. And what is that another not easy way? :)


0
 
LVL 1

Expert Comment

by:rvicentiu
ID: 9689662
you can install a WH_GETMESSAGE hook with SetWindowsHookEx and intercept for example the WM_MOUSEMOVE message to get the text from the window it was being sent to
0
 

Author Comment

by:MarkoB
ID: 9694398
ok. I managed to get text, but sometimes it gets too large to analyse big amounts of text, For 99% of cases I just need a single word (at mouse cursor),
the easier task would be to get just a selected text,
the only message I know is EM_GETSELTEXT, but that works fine for RichEdit,
but
how to get selected text from Internet Explorer, Outlook, or Word?
I mean without asking users to copy that to clipboard.
0
 

Author Comment

by:MarkoB
ID: 9731210
It looks that it is not possible without some OCR code. So I acceppt the answer fot the rivcentiu answer. Although I didn't managed to do, what I intended to do - to get a word at mouse cursor.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question