Forum Xamarin.iOS

CoreGraphics.CGEvent.CreateTap always returning null?

I'm trying to log key presses using CoreGraphics.CGEvent.CreateTap, but the call is always returning null. The app has Accessibility access, and I've also tried running with sudo to no avail. Is there anything else I need to set to allow the tap to be created? See below for my code:

var eventTap = CoreGraphics.CGEvent.CreateTap(CGEventTapLocation.Session, CGEventTapPlacement.HeadInsert, CGEventTapOptions.Default, CGEventMask.KeyDown | CGEventMask.FlagsChanged, (IntPtr tapProxyEvent, CGEventType eventType, IntPtr eventRef, IntPtr userInfo) => {
                if (eventType != CGEventType.KeyDown && eventType != CGEventType.FlagsChanged) return eventRef;

                // TODO - get key code
                return eventRef;
            }, IntPtr.Zero);

            // eventTap is always null?
            var runLoopSource = eventTap.CreateRunLoopSource();
Sign In or Register to comment.