此解决方案使用 Cocoa 框架。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
Carbon
Cocoa
编辑:感谢technomarge,更多信息在这里