【问题标题】:How to capture key down events at application level in Xamarin.Mac如何在 Xamarin.Mac 中的应用程序级别捕获按键事件
【发布时间】:2019-05-03 12:16:22
【问题描述】:

我有一个 Xamarin.Forms 应用程序,并使用主窗口中的 PreviewKeyDown 事件成功捕获 WPF 中的应用程序级按键事件。

如何在 AppDelegate 或其他方式中为 Xamarin.Mac 做同样的事情?

【问题讨论】:

    标签: macos xamarin xamarin.forms xamarin.mac


    【解决方案1】:

    您可以在本地级别的 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);
    }
    
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    • 2012-01-20
    • 2011-05-26
    • 2012-12-07
    • 1970-01-01
    相关资源
    最近更新 更多