检测文本光标 [英] Detecting Text Cursor

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

问题描述

有没有办法在任何地方检测文本光标图标。就像我在这个文本字段中写的一样,我的程序可以检测到这里启用了文本光标,并且可能在检测后生成任何事件。

Is there any way to detect text cursor icon anywhere. Like I am writing in this text field, my program could detect that text cursor is enabled here, and possibly generate any event after detection.

推荐答案

没有光标你形容它。 文本光标实际上称为插入符号或插入点。它只是一行或其他符号,定期绘制和删除,以向用户显示下一个字符的输入位置。没有全局事件或其他机制通知何时绘制符号的位置。



然而,您可以通过 GetForegroundWindow [ ^ ]然后调用< a href =https://msdn.microsoft.com/en-us/library/windows/desktop/ms648402%28v=vs.85%29.aspx> GetCaretPos [ ^ ]获取客户端窗口坐标中的插入位置。如果当前窗口没有插入标记,则可能会失败。
There is no cursor as you describe it. The "text cursor" is really called the "caret", or insertion point. It's just a line or other symbol that is periodically drawn and removed to show the user where the next character is going to be typed. There is no global event or other mechanism that notifies when are where the symbol is drawn.

You can however get the window that currently has the input focus with GetForegroundWindow[^] and then call GetCaretPos[^] to get the caret position in the client window coordinates. This can fail if the current window doesn't have a caret.


您可以尝试使用: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648402%28v=vs.85%29.aspx



使用C#,您可以通过P / Invoke使用它: http://www.pinvoke.net/default.aspx/user32.getcaretpos



注意如果有些控件当插入符号处于焦点时,此函数将返回true,否则它将返回false,因此您可以隐藏键盘。



注意与解决方案1的区别:那里无需调用任何其他功能。此功能为您提供当前插入位置(如果有)全局到桌面。



小问题是:某些应用程序可以处理键盘输入,但不能使用官方 Windows插入API。但你可以尝试一下,看看它的情况经常发生。对于这种情况,您可以选择禁用自动隐藏功能。



对于虚拟键盘本身,它可能存在某些问题;所以请在我过去的答案中看到我对这个主题的建议:

应用程序焦点的输入和丢失

在BACKSPACE按钮上编程

创建一个虚拟键盘



-SA
You can try to use: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648402%28v=vs.85%29.aspx.

With C#, you can use it through P/Invoke: http://www.pinvoke.net/default.aspx/user32.getcaretpos.

Note that if some control with the caret is in focus, this function will return true, otherwise it will return false, so you can hide your keyboard.

Note the difference with Solution 1: there is no need to call any other function. This function gives you current caret position (if any) global to the desktop.

On little problem is: some applications can handle keyboard input, but not use "official" Windows caret API. But you can try it out to see how often it might be the case. For such cases, you can have an option to disable your auto-hide feature.

As to the virtual keyboard itself, it can have certain problems; so please see my advice on this topic in my past answers:
Application focus getting and losing,
Programming on BACKSPACE button,
Creating a Virtual Keyboard.

—SA


这篇关于检测文本光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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