如何在Windows中的光标下获取光标? [英] How do I get word under my cursor on the screen in windows?

查看:152
本文介绍了如何在Windows中的光标下获取光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以从Windows屏幕上的光标位置读取单词。

但是,我想知道我需要使用的特定功能。我假设所有这些都可以使用Windows API完成。如果这里的任何人做过类似的事情,请引导我完成这个...



我想写一个在光标下读取和翻译单词的应用程序。我知道那里有类似的程序,但我想自己提高我的编程知识。



谢谢。

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.

推荐答案

本文中@ Mircea-Puiu提供的工具是您想要的: CatchCulator [ ^ ]?



他还有一个更新的: CatchCulator Suite for .NET [ ^ ]
Is the tool presented by @Mircea-Puiu in this article what you want: CatchCulator[^]?

He also has a newer one : CatchCulator Suite for .NET[^]


首先,通过读取光标下的单词是什么意思...

其次你的意思是读取鼠标光标当前指向的字符序列在。如果对第二个问题是肯定的,那么我可以说它是可能的(虽然我没有做过这样的事情)如果你自己推出自己的应用程序。

如果你不是,那么你将不得不开发一个可能作为服务运行的全局鼠标钩子。
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.


我没有尝试过这样的事情,但这样一个项目的可行性很大程度上取决于关于你究竟想要实现的目标。请描述你想要进一步指导的确切场景。



现在我将假设最简单的场景,这是我能想到的唯一场景你可以通过合理的努力来实现你的目标:



场景(I):

您已经编写了一个应用程序(可能还有其他内容)显示一个文本窗口。您可以完全控制该窗口中显示的文本,即您可以访问或编写了在屏幕上绘制每个单独字符的代码(而不是使用文本编辑框),并且您可以访问和覆盖鼠标事件对于那个窗口。



场景解决方案(I):

1.为鼠标移动写一个覆盖( )事件处理程序。关于任何类型的GUI库的覆盖事件处理程序有很多代码示例,因此我不会详细介绍。重要的是 OnMouseMove()事件将为您提供当前鼠标位置的X和Y坐标。

2.写一个使用鼠标位置查找在该位置绘制的单词的函数。显然,你需要一些方法来反向设计你所绘制的单词的位置。但是,如果绘图功能不仅绘制单词,而且还存储包含绘制每个单词的矩形区域的信息的查找表,则可以大大简化此功能。



其他场景:

从上面的步骤可以看出,程序在很大程度上取决于绘制单词的方式和位置。如果你缺乏这方面的知识,那么在一个位置找到单词的唯一方法就是进行广泛的图像分析,寻找绘制的字符和单词。由于文本可以用非常不同的字体,大小,样式和颜色打印,这是一项非常困难的任务。



可能存在中间场景,你不知道如何绘制单词,但可以访问它们被绘制的窗口,以及某种程度上,绘图的应用程序或库。可以通过自动化或API调用获取光标下的文本。但是,这会将您的功能限制在该特定应用程序或库中。
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.


这篇关于如何在Windows中的光标下获取光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆