Получение всей мультисенсорной сенсорной панели вводится в Какао

https://хром установки www.npmjs.com/package/chromium

npm

окна For:

\node_modules\chromium\lib\chromium\chrome-win\chrome.exe

11
задан Scott Greenlay 5 September 2009 в 14:59
поделиться

1 ответ

ОБНОВЛЕНИЕ: мой ответ ниже больше не работает. См. Ответ здесь .

Обычно для этого необходимо использовать Quartz Event Tap, хотя события касания, похоже, не «официально» поддерживаются CGEvent API. Типы событий без мультитач в NSEvent.h, похоже, соответствуют типам CGEvent в CGEventTypes.h, поэтому мультисенсорные, вероятно, будут работать, даже если они не задокументированы.

Чтобы заблокировать распространение событий, вам нужно вернуть NULL из обратного вызова касания события.

Вам понадобится такой код:

#import <ApplicationServices/ApplicationServices.h>

//assume CGEventTap eventTap is an ivar or other global

void createEventTap(void)
{
 CFRunLoopSourceRef runLoopSource;

 //listen for touch events
 //this is officially unsupported/undocumented
 //but the NSEvent masks seem to map to the CGEvent types
 //for all other events, so it should work.
 CGEventMask eventMask = (
  NSEventMaskGesture       |
  NSEventMaskMagnify       |
  NSEventMaskSwipe         |
  NSEventMaskRotate        |
  NSEventMaskBeginGesture  |
  NSEventMaskEndGesture
 );

 // Keyboard event taps need Universal Access enabled, 
 // I'm not sure about multi-touch. If necessary, this code needs to 
 // be here to check whether we're allowed to attach an event tap
 if (!AXAPIEnabled()&&!AXIsProcessTrusted()) { 
  // error dialog here 
  NSAlert *alert = [[[NSAlert alloc] init] autorelease];
  [alert addButtonWithTitle:@"OK"];
  [alert setMessageText:@"Could not start event monitoring."];
  [alert setInformativeText:@"Please enable \"access for assistive devices\" in the Universal Access pane of System Preferences."];
  [alert runModal];
  return;
 } 


 //create the event tap
 eventTap = CGEventTapCreate(kCGHIDEventTap, //this intercepts events at the lowest level, where they enter the window server
        kCGHeadInsertEventTap, 
        kCGEventTapOptionDefault, 
        eventMask,
        myCGEventCallback, //this is the callback that we receive when the event fires
        nil); 

 // Create a run loop source.
 runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);

 // Add to the current run loop.
 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

 // Enable the event tap.
 CGEventTapEnable(eventTap, true);
}


//the CGEvent callback that does the heavy lifting
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef theEvent, void *refcon)
{
 //handle the event here
 //if you want to capture the event and prevent it propagating as normal, return NULL.

 //if you want to let the event process as normal, return theEvent.
 return theEvent;
}
2
ответ дан 3 December 2019 в 10:44
поделиться