Get notified when something is added to NSPasteboard

前端 未结 2 1994
野趣味
野趣味 2021-02-06 02:58

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.

S

2条回答
  •  醉梦人生
    2021-02-06 03:16

    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).

提交回复
热议问题