从操作系统获取事件

 2023-01-19    445  

问题描述

我在Windows上工作,但我被困在Mac上.我有佳能SDK,并在上面构建了JNA包装器.它在Windows上运行良好,需要Mac的帮助.
在SDK中,有一个函数可以注册回调函数.基本上,当事件发生在相机中时,它调用回调函数.

在Windows上,注册后,我需要使用User32进行事件并通过以下方式派遣事件.

从操作系统获取事件

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中找不到类似的类.我该如何处理这个?

ps:JNA api “> api unix for unix is广泛,我无法弄清楚要寻找什么. 参考可能会有所帮助

推荐答案

此解决方案正在使用可可框架.可可被弃用,我不知道其他任何替代解决方案.但是下面的作用像魅力.

最后,我使用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类中提到的其他功能将是有用的.

I think Carbon framework documentation 将提供更多的见解和灵活性来解决问题.除Carbon外,在论坛中,人们还提到了解决Cocoa的解决,但我没有知道.

.

编辑:感谢 technomarge ,更多信息,更多信息在这里

以上所述是小编给大家介绍的从操作系统获取事件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/25805.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。