如何在Xamarin.Mac中的控制台应用程序上捕获kmouse事件,NSEvent已禁用。
答案 0 :(得分:0)
我知道如何使用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;
}