全球鼠标在可可中移动事件 [英] Global Mouse Moved Events in Cocoa
问题描述
有没有办法在Cocoa中注册全局鼠标移动的事件?我能够使用Carbon的 InstallEventHandler()
注册事件,但是更喜欢Cocoa等价物。我找了 NSNotificationCenter
事件,但似乎没有任何公共活动名称(是否有私人活动?)
Is there a way to register for global mouse moved events in Cocoa? I was able to register for the events using Carbon's InstallEventHandler()
, but would prefer a Cocoa equivalent. I have looked for NSNotificationCenter
events, but there doesn't seem to be any public event names (are there private ones?)
或者,是否可以使用 NSTrackingArea
用于具有 clearColor
背景的视图?
Alternatively, is there a way to use NSTrackingArea
for views with a clearColor
background?
该应用程序只是雪豹。
推荐答案
在SnowLeopard有一个新类方法on NSEvent
这正是你想要的: +(id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void(^ )block
。您将需要 mask = NSMouseMovedMask
。
In SnowLeopard there is a new class method on NSEvent
which does exactly what you want: + (id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void (^)(NSEvent*))block
. You’ll want mask = NSMouseMovedMask
.
这篇关于全球鼠标在可可中移动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!