// Registers callbacks for device addition and removal. These callbacks
        // are called when we run the loop in CheckDevicesMode
        void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
        {
            try{
                UnityEngine.Debug.Log("OSXHIDInterface> RegisterHIDCallbacks");

                Native.IOHIDManagerRegisterDeviceMatchingCallback(
                    hidmanager, HandleHIDDeviceAdded, IntPtr.Zero);
                Native.IOHIDManagerRegisterDeviceRemovalCallback(
                    hidmanager, HandleHIDDeviceRemoved, IntPtr.Zero);
                Native.IOHIDManagerScheduleWithRunLoop(hidmanager, RunLoop, InputLoopMode);

                //Native.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
                Native.IOHIDManagerSetDeviceMatchingMultiple(hidmanager, DeviceTypes.typeRef);

                Native.CFRelease(DeviceTypes.typeRef);


                IOReturn result = Native.IOHIDManagerOpen(hidmanager, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);

                if (result == IOReturn.kIOReturnSuccess)
                {
                    Native.CFRunLoopRunInMode(InputLoopMode, 0.0, true);

                    hidCallbacksRegistered = true;
                }
                else
                {
                    UnityEngine.Debug.LogError("OSXHIDInterface can't open hidmanager! Error:" + result);
                }
            }catch (Exception ex) {
                UnityEngine.Debug.LogException(ex);
            }
        }
Пример #2
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

            HandleDeviceAdded         = DeviceAdded;
            HandleDeviceRemoved       = DeviceRemoved;
            HandleDeviceValueReceived = DeviceValueReceived;

            hidmanager = CreateHIDManager();
            RegisterHIDCallbacks(hidmanager);
        }
Пример #3
0
        // Registers callbacks for device addition and removal. These callbacks
        // are called when we run the loop in CheckDevicesMode
        void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
        {
            NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                hidmanager, HandleDeviceAdded, IntPtr.Zero);
            NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                hidmanager, HandleDeviceRemoved, IntPtr.Zero);
            NativeMethods.IOHIDManagerScheduleWithRunLoop(hidmanager,
                                                          RunLoop, InputLoopMode);

            NativeMethods.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
            NativeMethods.IOHIDManagerOpen(hidmanager, IOOptionBits.Zero);

            OpenTK.Platform.MacOS.Carbon.CF.CFRunLoopRunInMode(InputLoopMode, 0.0, true);
        }
        public OSXHIDInterface()
        {
            __drivers = new List <IDriver>();

            __ports = new string[20];



            HandleHIDDeviceAdded   = HidDeviceAdded;
            HandleHIDDeviceRemoved = HidDeviceRemoved;
            HandleDeviceRemoved    = DeviceRemoved;

            CFDictionaryRef[] dictionaries;



            dictionaries = new CFDictionaryRef[3];

            //create 3 search patterns by Joystick,GamePad and MulitAxisController

            // base.typeRef = CFLibrary.CFDictionaryCreate(IntPtr.Zero,keyz,values,keys.Length,ref kcall,ref vcall);



            dictionaries[0] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop, (uint)Native.HIDUsageGD.Joystick);

            dictionaries[1] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop, (uint)Native.HIDUsageGD.GamePad);

            dictionaries[2] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop, (uint)Native.HIDUsageGD.MultiAxisController);



            DeviceTypes = new Native.CFArray(dictionaries);


            //create Hid manager
            hidmanager = Native.IOHIDManagerCreate(IntPtr.Zero, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);
        }
Пример #5
0
 public static extern void IOHIDManagerSetDeviceMatchingMultiple(
     IOHIDManagerRef manager,
     CFArrayRef multiple);
Пример #6
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

            HandleDeviceAdded = DeviceAdded;
            HandleDeviceRemoved = DeviceRemoved;
            HandleDeviceValueReceived = DeviceValueReceived;

            // For retrieving input directly from the hardware
            hidmanager = CreateHIDManager();
            RegisterHIDCallbacks(hidmanager);

            // For retrieving the global cursor position
            RegisterMouseMonitor();
        }
Пример #7
0
 public static extern void IOHIDManagerSetDeviceMatching(
     IOHIDManagerRef manager,
     CFDictionaryRef matching) ;
Пример #8
0
 public static extern void IOHIDManagerScheduleWithRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Пример #9
0
 public static extern void IOHIDManagerRegisterDeviceMatchingCallback(
     IOHIDManagerRef inIOHIDManagerRef,
     IOHIDDeviceCallback inIOHIDDeviceCallback,
     IntPtr inContext);
Пример #10
0
 public static extern IOReturn IOHIDManagerOpen(
     IOHIDManagerRef manager,
     IOOptionBits options);
Пример #11
0
 public static extern void IOHIDManagerSetDeviceMatching(
     IOHIDManagerRef manager,
     CFDictionaryRef matching);
Пример #12
0
 public static extern void IOHIDManagerScheduleWithRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Пример #13
0
 public static extern void IOHIDManagerRegisterDeviceRemovalCallback(
     IOHIDManagerRef inIOHIDManagerRef,
     IOHIDDeviceCallback inIOHIDDeviceCallback,
     IntPtr inContext);
		public OSXHIDInterface()
		{
			__drivers = new List<IDriver>();

			__ports = new string[20];


			
			HandleHIDDeviceAdded = HidDeviceAdded;
			HandleHIDDeviceRemoved = HidDeviceRemoved;
			HandleDeviceRemoved = DeviceRemoved;
			
			CFDictionaryRef[] dictionaries;
			
			
			
			
			
			
			dictionaries = new CFDictionaryRef[3];
			
			//create 3 search patterns by Joystick,GamePad and MulitAxisController
			
			// base.typeRef = CFLibrary.CFDictionaryCreate(IntPtr.Zero,keyz,values,keys.Length,ref kcall,ref vcall); 
			
			
			
			
			dictionaries[0] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop,(uint)Native.HIDUsageGD.Joystick);			
			
			dictionaries[1] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop,(uint)Native.HIDUsageGD.GamePad);
			
			dictionaries[2] = CreateDeviceMatchingDictionary((uint)Native.HIDPage.GenericDesktop,(uint)Native.HIDUsageGD.MultiAxisController);
			
			
			
			
			
			
			DeviceTypes= new Native.CFArray (dictionaries);
			
			
			//create Hid manager	
			hidmanager = Native.IOHIDManagerCreate(IntPtr.Zero,(int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);
			
			

			
			
			
			
		}
		// Registers callbacks for device addition and removal. These callbacks
		// are called when we run the loop in CheckDevicesMode
		void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
		{
			try{
				UnityEngine.Debug.Log("OSXHIDInterface> RegisterHIDCallbacks");

				Native.IOHIDManagerRegisterDeviceMatchingCallback(
                hidmanager, HandleHIDDeviceAdded, IntPtr.Zero);
            Native.IOHIDManagerRegisterDeviceRemovalCallback(
                hidmanager, HandleHIDDeviceRemoved, IntPtr.Zero);
            Native.IOHIDManagerScheduleWithRunLoop(hidmanager,RunLoop, InputLoopMode);

            //Native.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
            Native.IOHIDManagerSetDeviceMatchingMultiple(hidmanager, DeviceTypes.typeRef);

				Native.CFRelease(DeviceTypes.typeRef);


            IOReturn result=Native.IOHIDManagerOpen(hidmanager, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);

				if(result==IOReturn.kIOReturnSuccess){
					Native.CFRunLoopRunInMode(InputLoopMode, 0.0, true);

					hidCallbacksRegistered=true;
				}else{
					UnityEngine.Debug.LogError("OSXHIDInterface can't open hidmanager! Error:"+result);
				}



            

			}catch(Exception ex){
				UnityEngine.Debug.LogException(ex);
						}
           
        }
Пример #16
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

            HandleDeviceAdded = DeviceAdded;
            HandleDeviceRemoved = DeviceRemoved;
            HandleDeviceValueReceived = DeviceValueReceived;

            hidmanager = CreateHIDManager();
            RegisterHIDCallbacks(hidmanager);
        }
Пример #17
0
		public static extern void IOHIDManagerSetDeviceMatchingMultiple(
			IOHIDManagerRef manager,
			CFArrayRef multiple);
Пример #18
0
 public static extern IOReturn IOHIDManagerClose(
     IOHIDManagerRef allocator, IOOptionBits options);
Пример #19
0
 public static extern void IOHIDManagerRegisterDeviceRemovalCallback(
     IOHIDManagerRef inIOHIDManagerRef,
     IntPtr inIOHIDDeviceCallback,
     IntPtr inContext);
Пример #20
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

            RunLoop = CF.CFRunLoopGetMain();
            if (RunLoop == IntPtr.Zero)
                RunLoop = CF.CFRunLoopGetCurrent();
            if (RunLoop == IntPtr.Zero)
            {
                Debug.Print("[Error] No CFRunLoop found for {0}", GetType().FullName);
                throw new InvalidOperationException();
            }
            CF.CFRetain(RunLoop);

            HandleDeviceAdded = DeviceAdded;
            HandleDeviceRemoved = DeviceRemoved;
            HandleDeviceValueReceived = DeviceValueReceived;

            // For retrieving input directly from the hardware
            hidmanager = CreateHIDManager();
            if (hidmanager == IntPtr.Zero)
            {
                Debug.Print("[Mac] Failed to create IO HID manager, HIDInput driver not supported.");
                throw new NotSupportedException();
            }

            RegisterHIDCallbacks(hidmanager);

            // For retrieving the global cursor position
            RegisterMouseMonitor();
        }
Пример #21
0
 public static extern void IOHIDManagerUnscheduleFromRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Пример #22
0
        void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (manual)
                {
                    if (MouseEventTapSource != IntPtr.Zero)
                    {
                        // Note: releasing the mach port (tap source)
                        // automatically releases the event tap.
                        CF.RunLoopRemoveSource(RunLoop, MouseEventTapSource, CF.RunLoopModeDefault);
                        CF.CFRelease(MouseEventTapSource);
                        MouseEventTapSource = IntPtr.Zero;
                    }

                    NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerUnscheduleFromRunLoop(
                        hidmanager, RunLoop, InputLoopMode);

                    foreach (var device in MouseDevices.Keys)
                    {
                        DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device);
                    }

                    foreach (var device in KeyboardDevices.Keys)
                    {
                        DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device);
                    }

                    foreach (var device in JoystickDevices.Keys)
                    {
                        DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device);
                    }

                    if (hidmanager != IntPtr.Zero)
                    {
                        NativeMethods.IOHIDManagerClose(hidmanager, IOOptionBits.Zero);
                        hidmanager = IntPtr.Zero;
                    }

                    if (RunLoop != IntPtr.Zero)
                    {
                        CF.CFRelease(RunLoop);
                    }
                }
                else
                {
                    Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
                }
                disposed = true;
            }
        }
Пример #23
0
 public static extern IOReturn IOHIDManagerOpen(
     IOHIDManagerRef manager,
     IOOptionBits options) ;
Пример #24
0
        // Registers callbacks for device addition and removal. These callbacks
        // are called when we run the loop in CheckDevicesMode
        void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
        {
            NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                hidmanager, HandleDeviceAdded, IntPtr.Zero);
            NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                hidmanager, HandleDeviceRemoved, IntPtr.Zero);
            NativeMethods.IOHIDManagerScheduleWithRunLoop(hidmanager,
                RunLoop, InputLoopMode);

            NativeMethods.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
            NativeMethods.IOHIDManagerOpen(hidmanager, IOOptionBits.Zero);
        }
Пример #25
0
        // Registers callbacks for device addition and removal. These callbacks
        // are called when we run the loop in CheckDevicesMode
        void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
        {
            NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                hidmanager, HandleDeviceAdded, IntPtr.Zero);
            NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                hidmanager, HandleDeviceRemoved, IntPtr.Zero);
            NativeMethods.IOHIDManagerScheduleWithRunLoop(hidmanager,
                RunLoop, InputLoopMode);

            NativeMethods.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
            NativeMethods.IOHIDManagerOpen(hidmanager, IOOptionBits.Zero);

            OpenTK.Platform.MacOS.Carbon.CF.CFRunLoopRunInMode(InputLoopMode, 0.0, true);
        }
Пример #26
0
 public static extern void IOHIDManagerRegisterDeviceMatchingCallback(
     IOHIDManagerRef inIOHIDManagerRef,
     IntPtr inIOHIDDeviceCallback,
     IntPtr inContext);