在 Windows 中获取鼠标光标下的单词 [英] Get the word under the mouse cursor in Windows

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

问题描述

大家好,

我和一个朋友正在讨论一个新项目的可能性:一个翻译程序,当你将鼠标悬停在任何控件中的任何单词上时,它会弹出一个翻译,即使是静态的、不可编辑的.我知道有很多浏览器插件可以在网页上做这种事情;我们正在考虑如何在系统范围内(在 Windows 上)执行此操作.

A friend and I are discussing the possibility of a new project: A translation program that will pop up a translation whenever you hover over any word in any control, even static, non-editable ones. I know there are many browser plugins to do this sort of thing on webpages; we're thinking about how we would do it system-wide (on Windows).

当然,关键的难点在于弄清楚用户悬停在上面的词.我知道 MSAA 和自动化,但据我所知,这些东西只允许您获取控件的全部内容,而不是鼠标所在的特定单词.

Of course, the key difficulty is figuring out the word the user is hovering over. I'm aware of MSAA and Automation, but as far as I can tell, those things only allow you to get the entire contents of a control, not the specific word the mouse is over.

我偶然发现了这个(专有)应用程序,它几乎可以完成我们想要做的事情:http://www.gettranslateit.com/

I stumbled upon this (proprietary) application that does pretty much exactly what we want to do: http://www.gettranslateit.com/

不知何故,他们几乎可以在任何应用程序中获得用户悬停在其上的确切词(在一些应用程序中似乎有问题,尤其是 Windows 资源管理器).它甚至以某种方式从明显自定义绘制的控件中获取文本.起初我认为它必须使用OCR.但即使我将字体缩小到如此之低以至于文本变成完全不可读的斑点,它仍然可以完美地识别单词.(然而,如果我将字体更改为 Wingdings,它就无法识别任何内容.但也许这是设计使然?)

Somehow they are able to get the exact word the user is hovering over in almost any application (It seems to have trouble in a few apps, notably Windows Explorer). It even grabs text out of obviously custom-drawn controls, somehow. At first I thought it must be using OCR. But even when I shrink the font so far down that the text becomes a completely unreadable blob, it can still recognize words perfectly. (And yet, it doesn't recognize anything if I change the font to Wingdings. But maybe that's by design?)

关于它是如何完成这个看似不可能的任务的任何想法?

Any ideas as to how it's achieving this seemingly impossible task?

它不适用于 Wingdings,但它适用于其他一些无意义的字体,所以我已经确认它不能是 OCR.

It doesn't work with Wingdings, but it does work with some other nonsense fonts, so I've confirmed it can't be OCR.

推荐答案

您可以捕获将文本输出到显示器的 GDI 调用,然后找出光标所在的单词的边界框.

You could capture the GDI calls that output text to the display, and then figure out which word's bounding box the cursor falls in.

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

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