从操作系统获取事件

从操作系统获取事件

问题描述:

我在Windows上工作,但在Mac上却卡在这里.我有佳能SDK,并在其上构建了JNA包装器.它在Windows上运行良好,在Mac上需要一些帮助. 在sdk中,有一个函数可以注册一个回调函数.基本上,当摄像机中发生事件时,它将调用回调函数.

I work on windows but I am stuck here on Mac. I have the Canon SDK and have built a JNA wrapper over it. It works well on windows and need some help with Mac. In the sdk, there is a function where one can register a callback function. Basically when an event occurs in camera, it calls the callback function.

在Windows上,注册后,我需要使用User32来获取事件并通过以下方式调度事件:

On windows, after registering, I need to use User32 to get the event and to dispatch the event by:

private static final User32 lib = User32.INSTANCE;
boolean hasMessage = lib.PeekMessage( msg, null, 0, 0, 1 ); // peek and remove
if( hasMessage ){
    lib.TranslateMessage( msg ); 
    lib.DispatchMessage( msg ); //message gets dispatched and hence the callback function is called
}

在api中,我在Mac中找不到类似的类.我该怎么办?

In the api, I do not find a similar class in Mac. How do I go about this one??

PS:Unix的JNA api 是广泛,我不知道要寻找什么. 引用可能有帮助

PS: The JNA api for unix is extensive and I could not figure out what to look for. The reference might help

此解决方案正在使用Cocoa框架.可可已弃用,我不知道有任何其他替代解决方案.但是下面的内容就像魅力一样.

This solution is using the Cocoa framework. Cocoa is deprecated and I am not aware of any other alternative solution. But the below works like charm.

最后,我找到了使用Carbon框架的解决方案.这是我的MCarbon接口,它定义了我需要的呼叫.

Finally I found the solution using Carbon framework. Here is my MCarbon interface which defines calls I need.

  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
  }

使用以下功能可以解决问题:

The solution to the problem is solved using the below function:

 NativeLong ReceiveNextEvent(NativeLong inNumTypes, EventTypeSpec[] inList, double inTimeout, byte inPullEvent, Pointer outEvent);

这完成了工作.根据文档-

This does the job. As per documentation -

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类中提到的其他功能也将很有用.

Also if not ReceiveNextEvent, then other functions as mentioned in MCarbon class above would be useful.

我认为Carbon框架文档将为解决问题提供更多的见识和灵活性.除了Carbon之外,在论坛中,人们还提到过使用Cocoa解决问题的方法,但是我没有人知道.

I think Carbon framework documentation would give more insights and flexibilities to solve the problem. Apart from Carbon, in forums people have mentioned about solving using Cocoa, but none I am aware of.

感谢 technomarge ,更多信息 查看更多