[英]How to capture key down events at application level in Xamarin.Mac
我有一個 Xamarin.Forms 應用程序,並使用主窗口中的 PreviewKeyDown 事件成功捕獲了 WPF 中的應用程序級按鍵按下事件。
如何在 AppDelegate 或其他方式中為 Xamarin.Mac 做同樣的事情?
您可以在本地級別的 AppDelegate 的DidFinishLaunching
中添加NSEvent
處理程序,以監視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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.