Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I know it is possible to read word from the position of the cursor on the windows screen.
However, I would like to know specific functions that I need to use. I assume that all these can be done using Windows API. If anyone here has ever done something similar, please guide me through this...

I would like to write an application which reads and translates word under the cursor. And I know there is similar program out there, but I would like to make my own to improve my programming knowledge.

Thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Feb-14 17:30pm    
You can improve you knowledge only if you do some work all by yourself. And this project would not make much sense. There is no a simple and reliable way to do it.
—SA

Is the tool presented by @Mircea-Puiu in this article what you want: CatchCulator[^]?

He also has a newer one : CatchCulator Suite for .NET[^]
 
Share this answer
 
First off what do you mean by reading words under the cursor...
Secondly Do you mean to read sequence of character that the mouse cursor is currently pointing at. If yes for the second question, then i can say it is possible (I haven not done such a thing though) if you are rolling out your own application your self.
And if you are not, then you will have to develop and a global mouse hook that will probably be running as a service.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Feb-14 17:33pm    
This is all nearly useless as "word" on screen could mean image (everything on screen is just one bitmap, there are no "words" there, they all lost on the way from code to screen) of some handwritten text. This is no less then image recognition, nothing simple. I don't think going in for it even makes any sense...
—SA
I've not tried such a thing, but the feasibility of such a project would very much depend on what, exactly, you are trying to achieve. Please describe the exact scenario you are thinking of for further instruction.

For now I'll assume the easiest of scenarios, which is the only one I can think of where you can achieve your goal with reasonable effort:

Scenario (I):
You have written an application that (possibly among other things) shows a text window. You have full control over the text displayed within that window, i.e. you have access to or have written the code that draws each individual character on the screen (as opposed to e. g. using a text edit box), and you can access and override mouse events for that window.

Solution for Scenario (I):
1. write an override for the MouseMove() event handler. There are plenty of code examples on overriding event handlers for any type of GUI library, so I won't go into further detail. The important thing is that the OnMouseMove() event will provide you with the X and Y coordinates of your current mouse position.
2. Write a function that uses the position of the mouse to find the word that is drawn at that position. Obviously, you need some way to reverse-engineer the positions of the words that you have drawn. However, you can greatly simplify this function if your drawing function not only draws the words, but also stores a lookup-table containing the info on the rectangular area that each word is drawn on.

Other Scenarios:
As you can see from the steps above, the program greatly depends on the knowledge of how and where the words are drawn. If you lack that knowledge, the only way to 'find the word' at a position, is do an extensive image analysis looking for drawn characters and words. Since text can be printed in very different fonts, sizes, styles, and colors, that is an incredibly difficult task.

There may be 'intermediate' scenarios where you don't exactly know how the words are drawn, but can access the windows they're drawn into, and, to some degree, the application or library that does the drawing. It may be possible to get the text under the cursor through automation or API calls. However, this will restrict your function to that particular application or library.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900