当将东西添加到NSPasteboard时收到通知 [英] Get notified when something is added to NSPasteboard

查看:493
本文介绍了当将东西添加到NSPasteboard时收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想收到通知如果有东西添加到NSPasteboard。如果我从任何其他程序复制文本,我希望我的应用程序知道它。

In my application I want to get notified if something is added into the NSPasteboard. If I copy an text from any other program I want my application to know about it.

在某个地方我读不能这样做。我应该创建一个计时器,并自己检查NSPasteboard的内容。

Somewhere I read it can't be done that way. I should create a timer and check the content of the NSPasteboard myself.

这是要做的方法吗?

推荐答案

是的,您必须轮询粘贴板以查看其内容是否已更改。这不是理想,但它是可能的。基本上,您有一个计时器,每秒触发一次或两次,并检查 - [NSPasteboard changeCount] 。如果 changeCount 更改,这意味着粘贴板的内容也已更改(或至少有一个新的所有者)。

Yes, you essentially have to poll the pasteboard to see if its contents have changed. It's not ideal, but it's possible. Basically, you have a timer that fires once or twice a second and checks the -[NSPasteboard changeCount]. If the changeCount changes, that means the contents of the pasteboard have also changed (or there's at least a new owner).

这篇关于当将东西添加到NSPasteboard时收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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