Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

get text(word) at mouse cursor from any program

Posted on 2003-11-04
8
Medium Priority
?
402 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 750 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: 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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

722 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