本地插入符号macos可可

本地插入符号macos可可

本文介绍了本地插入符号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

您的帖子似乎表明您不希望使用Accessibility API(但如果不使用accessibility 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可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:36