Xamarin.Mac 如何在控制台应用程序中捕获鼠标事件

How to capture mouse events at console application in Xamarin.Mac

如何在 Xamarin.Mac 中的控制台应用程序中捕获 kmouse 事件,NSEvent 已禁用。

我知道如何使用CGEvent捕获鼠标事件,如下:

    public static void Main(string[] args)
    {
        NSApplication.Init();

        var call = new CGEvent.CGEventTapCallback(Callback);

        var data = new IntPtr();

        var eventTap = CGEvent.CreateTap(CGEventTapLocation.HID, CGEventTapPlacement.TailAppend, CGEventTapOptions.Default, CGEventMask.MouseMoved, call, data);

        var cfMachPort = new CFMachPort(eventTap.Handle);

        CFRunLoopSource runLoopSource = cfMachPort.CreateRunLoopSource();

        CFRunLoop.Main.AddSource(runLoopSource, CFRunLoop.ModeCommon);

        CGEvent.TapEnable(eventTap);

        CFRunLoop.Main.Run();

    }

    public static IntPtr Callback(IntPtr eventTap, CGEventType cGEventType, IntPtr eventRef, IntPtr usrInfo)
    {
        Console.WriteLine("鼠标移动了");
        return eventTap;
    }