如何获取当前鼠标(指针)在 X 中的位置坐标
这可以是一些示例 C 代码,也可以是一个实用程序,可以在 gui 或控制台上向我显示这并不重要,但我必须能够“命令”它在准确的时间获取坐标,这使得xev 不是很有用(我可以弄清楚)。
This can either be some sample C code or a utility that will show me either gui or on the console it doesn't matter, but I have to be able to "command" it to grab the co-ordinates at an exact time which makes xev not very useful (that I could figure out).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无论如何,我不是 C 程序员,但我看了几个在线教程,认为这就是您应该读取当前鼠标位置的方式。这是我自己的代码,之前我没有对 Xlib 进行任何操作,因此它可能会被完全破坏(例如,错误处理程序不应该对每个错误不执行任何操作),但它可以工作。所以这是另一个解决方案:
I'm not a C programmer by any means but I looked at a couple of online tutorials and think this is how you are supposed to read the current mouse position. This is my own code and I'd done nothing with Xlib before so it could be completely broken (for example, the error handler shouldn't just do nothing for every error) but it works. So here is another solution:
xdotool 可能是最好的工具。
对于 C,您可以使用 libxdo。
xdotool might be the best tool for this.
For C, you can use libxdo.
实际上,xev 非常有用,如果您向它提供使用 xwininfo 抓取的窗口 id,那么它可以轻松地为您执行此任务。毫无疑问,还有更优雅的解决方案,但它确实有效。
Actually, xev is very useful if you supply it with the window id grabbed using xwininfo, then it can easily perform this task for you. There are no doubt much more elegant solutions but it works.
xinput 可用于打印任何输入设备的完整设备状态。
首先你需要发现你的设备ID:
然后你可以询问状态:
或者只是一个循环:
xinput can be used to print the full device state of any input device.
First you need to discover your device id:
then you can ask for state:
Or just a loop: