当前位置: 代码迷 >> 综合 >> Mac OS NSViewController获取-(void)keyDown:(NSEvent*)event事件
  详细解决方案

Mac OS NSViewController获取-(void)keyDown:(NSEvent*)event事件

热度:54   发布时间:2023-12-08 20:55:19.0

要想NSViewController获取-(void)keyDown:(NSEvent*)event事件 得在viewController里加上

[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent * _Nullable(NSEvent * _Nonnull aEvent) { 
[self keyDown:aEvent]; 
return aEvent; 
}]; 
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^NSEvent * _Nullable(NSEvent * _Nonnull aEvent) { 
[self flagsChanged:aEvent]; 
return aEvent; 
}]; 

 

  相关解决方案