此解決方案使用Cocoa框架。可可被棄用,我不知道任何其他替代解決方案。但下面的作品像魅力。
最後我找到了使用Carbon
框架的解決方案。這是我的MCarbon
接口,它定義了我需要的呼叫。
public interface MCarbon extends Library {
MCarbon INSTANCE = (MCarbon) Native.loadLibrary("Carbon", MCarbon.class);
Pointer GetCurrentEventQueue();
int SendEventToEventTarget(Pointer inEvent, Pointer intarget);
int RemoveEventFromQueue(Pointer inQueue, Pointer inEvent);
void ReleaseEvent(Pointer inEvent);
Pointer AcquireFirstMatchingEventInQueue(Pointer inQueue,NativeLong inNumTypes,EventTypeSpec[] inList, NativeLong inOptions);
//... so on
}
該問題的解決方案是使用下面的函數解決:
NativeLong ReceiveNextEvent(NativeLong inNumTypes, EventTypeSpec[] inList, double inTimeout, byte inPullEvent, Pointer outEvent);
這做這項工作。按照文檔 -
This routine tries to fetch the next event of a specified type.
If no events in the event queue match, this routine will run the
current event loop until an event that matches arrives, or the
timeout expires. Except for timers firing, your application is
blocked waiting for events to arrive when inside this function.
另外,如果不ReceiveNextEvent
,如在MCarbon
類提到然後其他功能上面將是有益的。
我認爲Carbon
框架documentation將提供更多的見解和靈活性來解決問題。除了Carbon
,在論壇上人們都提到過使用Cocoa
來解決問題,但沒有人知道。
編輯:多虧了technomarge,更多信息here
你可能會想看看GCEventRef,https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference .html – 2013-03-08 05:53:10
JNA的unix平臺映射大部分都是針對X11的,並沒有太多專門針對OS X的。[Rococoa](http://code.google.com/p/rococoa/)有更多的方法OS X映射。 – technomage 2013-03-08 16:35:16
@technomage我現在不能轉向Rococoa,因爲那樣我將不得不重寫代碼。 Windows已經正常工作。我只是需要一些技術來獲得消息 – Jatin 2013-03-09 08:32:45