本机插入符号位置 macos 可可 [英] Native caret position macos cocoa

查看:42
本文介绍了本机插入符号位置 macos 可可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用 cocoa 或 appleScript 在 Mac High Sierra 中的任何应用程序中获取全局插入符号位置.我已经使用 NSEvent 来获取键盘和鼠标挂钩,但是有没有办法获取插入符号位置挂钩?

I want to be able to get the global caret position inside any application in Mac High Sierra using cocoa or appleScript. I already use NSEvent to get the keyboard and mouse hook but is there a way to get the caret position hook?

插入符号与鼠标位置不同.它在按键事件或鼠标点击时移动.在 Windows 中,您几乎可以在任何地方获得插入符号位置.我想知道是否有 macos 的等价物.

The caret is different from the mouse position. It moves on key event or mouse click. In windows, you can get the caret position almost anywhere. I want to know if there is the equivalent for macos.

我想在文本插入符号上显示一个弹出窗口,如果我在键盘上输入或换行,它会随着文本移动.我尝试获取键事件的位置,(locationInWindow)但它让我回到鼠标位置.我不是沙箱所以我什至可以调用applescripts

I want to show a popup over the text caret, if i type on the keyboard or line return, it moves with the text.I tried getting the position of the key event, (locationInWindow) but it give me back the mouse position. I am not sandbox so i can even call applescripts

更新:可以通过使用可访问性 API 获取插入符号前的字母边界来实现此目的.

UPDATE : It is possible doing this by getting the bounds of the letter before the caret with the use of accessibility API.

谢谢

推荐答案

我还没有机会亲自尝试,所以你可能会在确认/拒绝这一点上击败我.

I don't have the opportunity to try it for myself just yet, so you might beat me to the punch of confirm/reject this.

UIEvent 具有 addGlobalMonitorForEventsMatchingMask:handler: 其中掩码可以具有 NSEventMaskCursorUpdate 的值,并且大概返回的 NSEvent 对象将包含一个可以对其进行操作(即转换到屏幕空间).

UIEvent has addGlobalMonitorForEventsMatchingMask:handler: where the mask can have a value of NSEventMaskCursorUpdate and presumably the returned NSEvent object will contain a coordinate that can be acted upon (i.e. converted to screen-space).

这里的警告是文档明确说明

Caveat here is the docs explicitly say

只有在启用辅助功能的情况下才能监控与按键相关的事件或者如果您的应用程序在可访问性访问方面受到信任(请参阅AXIsProcessTrusted).

Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access (see AXIsProcessTrusted).

您的帖子似乎暗示您不希望使用辅助功能 API(但如果不使用辅助功能 API"),因此可能意味着您在特定的需求组合中不走运你寻求实现.

Your post seems to suggest that you do not wish to use Accessibility API ("but if not using accessibility API") so that may mean you're out of luck in the specific combination of requirements you seek to fulfill.

这篇关于本机插入符号位置 macos 可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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