예제 #1
0
        public static void Initialize(Engine _engine)
        {
            runLoop = MacNative.CFRunLoopGetMain ();
            if (runLoop == IntPtr.Zero) {
                runLoop = MacNative.CFRunLoopGetCurrent ();
            }
            if (runLoop == IntPtr.Zero) {
                throw(new Exception ("[mac-input] unable to get a RunLoop"));
            }
            // avoid the RunLoop to be garbaged
            MacNative.CFRetain (runLoop);

            System.IntPtr hidManager = MacNative.IOHIDManagerCreate (IntPtr.Zero, IntPtr.Zero);
            if (hidManager == IntPtr.Zero) {
                throw(new Exception ("[mac-input] unable to get a HidManager()"));
            }

            DeviceAddedCallback = DeviceAdded;
            MacNative.IOHIDManagerRegisterDeviceMatchingCallback (hidManager, DeviceAddedCallback, IntPtr.Zero);

            DeviceRemovedCallback = DeviceRemoved;
            MacNative.IOHIDManagerRegisterDeviceRemovalCallback (hidManager, DeviceRemovedCallback, IntPtr.Zero);

            DeviceInputCallback = InputReceived;

            MacNative.IOHIDManagerScheduleWithRunLoop (hidManager, runLoop, defaultLoopMode);

            MacNative.IOHIDManagerSetDeviceMatching (hidManager, IntPtr.Zero);

            MacNative.IOHIDManagerOpen (hidManager, IntPtr.Zero);

            engine = _engine;
            engine.OnAfterUpdate += new Engine.AfterUpdateEventHandler (RunLoopStep);
        }
예제 #2
0
        public static void Initialize(Engine _engine)
        {
            runLoop = MacNative.CFRunLoopGetMain();
            if (runLoop == IntPtr.Zero)
            {
                runLoop = MacNative.CFRunLoopGetCurrent();
            }
            if (runLoop == IntPtr.Zero)
            {
                throw(new Exception("[mac-input] unable to get a RunLoop"));
            }
            // avoid the RunLoop to be garbaged
            MacNative.CFRetain(runLoop);

            System.IntPtr hidManager = MacNative.IOHIDManagerCreate(IntPtr.Zero, IntPtr.Zero);
            if (hidManager == IntPtr.Zero)
            {
                throw(new Exception("[mac-input] unable to get a HidManager()"));
            }


            DeviceAddedCallback = DeviceAdded;
            MacNative.IOHIDManagerRegisterDeviceMatchingCallback(hidManager, DeviceAddedCallback, IntPtr.Zero);

            DeviceRemovedCallback = DeviceRemoved;
            MacNative.IOHIDManagerRegisterDeviceRemovalCallback(hidManager, DeviceRemovedCallback, IntPtr.Zero);

            DeviceInputCallback = InputReceived;

            MacNative.IOHIDManagerScheduleWithRunLoop(hidManager, runLoop, defaultLoopMode);

            MacNative.IOHIDManagerSetDeviceMatching(hidManager, IntPtr.Zero);

            MacNative.IOHIDManagerOpen(hidManager, IntPtr.Zero);

            engine = _engine;
            engine.OnAfterUpdate += new Engine.AfterUpdateEventHandler(RunLoopStep);
        }