检测文本光标

编程入门 行业动态 更新时间:2024-10-18 08:34:08
本文介绍了检测文本光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 [ ^ ]然后调用 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.

您可以尝试使用: msdn.microsoft/en-us/library/windows/desktop/ms648402%28v=vs.85%29.aspx 。 使用C#,您可以通过P / Invoke使用它: www.pinvoke/default.aspx/user32.getcaretpos 。 注意如果有些控件当插入符号处于焦点时,此函数将返回true,否则它将返回false,因此您可以隐藏键盘。 注意与解决方案1的区别:那里无需调用任何其他功能。此功能为您提供当前插入位置(如果有)全局到桌面。 小问题是:某些应用程序可以处理键盘输入,但不能使用官方 Windows插入API。但你可以尝试一下,看看它的情况经常发生。对于这种情况,您可以选择禁用自动隐藏功能。 对于虚拟键盘本身,它可能存在某些问题;所以请在我过去的答案中看到我对这个主题的建议: 应用程序焦点的输入和丢失, 在BACKSPACE按钮上编程, 创建一个虚拟键盘。
-SA
You can try to use: msdn.microsoft/en-us/library/windows/desktop/ms648402%28v=vs.85%29.aspx. With C#, you can use it through P/Invoke: www.pinvoke/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

更多推荐

检测文本光标

本文发布于:2023-11-29 20:20:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:光标   文本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!