Get events from OS

孤人 提交于 2019-12-04 22:20:28
Jatin

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.

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.

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

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.

Edit: Thanks to technomarge, more information here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!