我需要在 MonoMac 中继承 NSApplication 以覆盖 NSApplication 的 sendEvent(C# 术语中的 SendEvent)方法,以便接收媒体键事件(Macbook 上的 Play、Pause、Next、Prev),如下所述:Listening to mac keyboard play/pause events在这里:https ://bitbucket.org/nkreeger/whitedragon/src/6f530c8a34a7/component/sbAppleMediaKeyController.mm
到目前为止,我想出了这段代码:
class MainClass
{
static void Main (string[] args)
{
MyApp.Init ();
MyApp.Main (args);
}
}
class MyApp : NSApplication
{
public override void SendEvent (NSEvent theEvent)
{
Console.WriteLine ("event received!");
base.SendEvent (theEvent);
}
public override void SetMainMenu (NSMenu aMenu)
{
Console.WriteLine ("main menu set!");
base.SetMainMenu (aMenu);
}
}
但是没有调用 SendEvent 或 SetMainMenu(我出于测试目的添加了它,因为在启动时应该调用一次 SetMainMenu),因为我没有得到任何控制台输出。
这样做的正确方法是什么?