获取Xorg下插入符号(输入文本光标)的X/Y位置? [英] Get X/Y position of caret (input text cursor) under Xorg?

查看:123
本文介绍了获取Xorg下插入符号(输入文本光标)的X/Y位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在X上运行的任何Linux应用(GTK,Qt,Electron等)中的用户输入上方显示一个弹出窗口.

I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.

我想出了创建弹出框的方法,现在我想弄清楚如何获取相对于屏幕的输入文本光标的坐标(键入时闪烁什么,不确定是否称为插入符号"?).

I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.

我知道我可以通过xdotool获取有关鼠标位置的信息:

I know I can get info on where the mouse with xdotool:

xdotool getmouselocation

除了文本光标之外,在当前聚焦的窗口中,我需要做同样的事情.

I would need the same thing but for the text cursor, in the currently focused window.

我不知道如何实现这一目标.我希望有人能指出正确的方向.

I have no idea how to achieve this. I would love if someone could point me in the right direction.

推荐答案

因此,在进行了一些研究之后,我能够找到实现此目的的一种方法:

So, after doing some research I was able to figure out one way to implement this:

  • 使用xdotool粘贴一些随机字符串
  • 使用OCR查找随机字符串的坐标
  • 使用xdotool删除随机字符串
  • use xdotool to paste some random string
  • use OCR to find coordinates of the random string
  • use xdotool to remove random string

问题在于这种方法非常慢(最多10秒,具体取决于屏幕上显示的文本数量.)

The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).

我还尝试过比较屏幕截图(在插入文本之前/之后),它的速度要快得多,但精确度要低得多.

I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.

这篇关于获取Xorg下插入符号(输入文本光标)的X/Y位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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