我有一个Xamarin.Forms应用程序,并使用主窗口中的PreviewKeyDown事件成功捕获了WPF中的应用程序级按键按下事件。
如何在AppDelegate中对Xamarin.Mac进行同样的处理?
答案 0 :(得分:1)
您可以在本地级别的AppDelegate的NSEvent
中添加DidFinishLaunching
处理程序,以监视NSEventMask
的任何组合。
public override void DidFinishLaunching(NSNotification notification)
{
NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.KeyDown, (NSEvent theEvent) =>
{
Console.WriteLine(theEvent);
return theEvent;
});
Forms.Init();
LoadApplication(new App());
base.DidFinishLaunching(notification);
}