// 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); } }
public HIDInput() { Debug.Print("Using HIDInput."); HandleDeviceAdded = DeviceAdded; HandleDeviceRemoved = DeviceRemoved; HandleDeviceValueReceived = DeviceValueReceived; hidmanager = CreateHIDManager(); RegisterHIDCallbacks(hidmanager); }
// 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); }
public static extern void IOHIDManagerSetDeviceMatchingMultiple( IOHIDManagerRef manager, CFArrayRef multiple);
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(); }
public static extern void IOHIDManagerSetDeviceMatching( IOHIDManagerRef manager, CFDictionaryRef matching) ;
public static extern void IOHIDManagerScheduleWithRunLoop( IOHIDManagerRef inIOHIDManagerRef, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
public static extern void IOHIDManagerRegisterDeviceMatchingCallback( IOHIDManagerRef inIOHIDManagerRef, IOHIDDeviceCallback inIOHIDDeviceCallback, IntPtr inContext);
public static extern IOReturn IOHIDManagerOpen( IOHIDManagerRef manager, IOOptionBits options);
public static extern void IOHIDManagerSetDeviceMatching( IOHIDManagerRef manager, CFDictionaryRef matching);
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); } }
public static extern IOReturn IOHIDManagerClose( IOHIDManagerRef allocator, IOOptionBits options);
public static extern void IOHIDManagerRegisterDeviceRemovalCallback( IOHIDManagerRef inIOHIDManagerRef, IntPtr inIOHIDDeviceCallback, IntPtr inContext);
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(); }
public static extern void IOHIDManagerUnscheduleFromRunLoop( IOHIDManagerRef inIOHIDManagerRef, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
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; } }
public static extern IOReturn IOHIDManagerOpen( IOHIDManagerRef manager, IOOptionBits options) ;
// 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); }
public static extern void IOHIDManagerRegisterDeviceMatchingCallback( IOHIDManagerRef inIOHIDManagerRef, IntPtr inIOHIDDeviceCallback, IntPtr inContext);