获取当前键盘光标位置

获取当前键盘光标位置

本文介绍了获取当前键盘光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像使用 mouseLocation 获取鼠标光标位置那样全局获取键盘光标(插入符号)当前位置的坐标?

Is there anyway to get coordinates for the current position of the keyboard cursor (caret) globally like you can for the mouse cursor position with mouseLocation?

推荐答案

最接近的方法是使用 OS X 的辅助功能协议.这是为了帮助残疾用户操作计算机,但许多应用程序不支持它,或者支持得不是很好.

The closest you can get would be to use OS X's Accessibility Protocol. This is intended to help disabled users operate the computer, but many applications don't support it, or do not support it very well.

程序类似于:

appRef = AXUIElementCreateApplication(appPID);
focusElemRef = AXUIElementCopyAttributeValue(appRef,kAXFocusedUIElementAttribute, &theValue)
AXUIElementCopyAttributeValue(focusElemRef, kAXSelectedTextRangeAttribute, &selRangeValue);
AXUIElementCopyParameterizedAttributeValue(focusElemRef, kAXBoundsForRangeParameterizedAttribute, adjSelRangeValue, &boundsValue);

由于对协议的支持参差不齐,对于许多应用程序,您将无法超越 FocusedUIElementAttribute 步骤,但这确实适用于某些应用程序.

Due to the spotty support for the protocol, with many applications you won't get beyond the FocusedUIElementAttribute step, but this does work with some applications.

这篇关于获取当前键盘光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:43