本文介绍了如何在Xamarin.Mac中捕获应用程序级别的按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Xamarin.Forms应用程序,并使用主窗口中的PreviewKeyDown事件成功捕获了WPF中的应用程序级键盘按下事件.
I have a Xamarin.Forms application and successfully capture application level key down events in WPF using the PreviewKeyDown event in the main window.
如何在AppDelegate中对Xamarin.Mac进行同样的处理?
How do I do the same thing for Xamarin.Mac in AppDelegate or otherwise?
推荐答案
您可以在本地级别的AppDelegate的 DidFinishLaunching
中添加 NSEvent
处理程序,以监视以下内容的任意组合: NSEventMask
.
You can add an NSEvent
handler in the AppDelegate's DidFinishLaunching
at the local level to monitor any combination of the 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);
}
这篇关于如何在Xamarin.Mac中捕获应用程序级别的按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!