예제 #1
0
        private static void DeviceAdded(System.IntPtr context, System.IntPtr res, System.IntPtr sender, System.IntPtr device)
        {
            if (MacNative.IOHIDDeviceOpen(device, IntPtr.Zero) == IntPtr.Zero)
            {
                if (MacNative.IOHIDDeviceConformsTo(device, HIDDesktop, HIDJoystick) ||
                    MacNative.IOHIDDeviceConformsTo(device, HIDDesktop, HIDGamePad) ||
                    MacNative.IOHIDDeviceConformsTo(device, HIDDesktop, HIDMultiAxis) ||
                    MacNative.IOHIDDeviceConformsTo(device, HIDDesktop, HIDWheel))
                {
                    System.IntPtr product     = MacNative.IOHIDDeviceGetProperty(device, MacNative.CFString("Product"));
                    string        productName = MacNative.CString(product);

                    int index = 0;
                    foreach (Engine.Joystick joystick in engine.joysticks)
                    {
                        if (joystick == null)
                        {
                            engine.joysticks [index]       = new Engine.Joystick();
                            engine.joysticks [index].index = index;
                            engine.joysticks [index].id    = device.ToInt64();
                            engine.joysticks [index].name  = productName;
                            MacNative.IOHIDDeviceRegisterInputValueCallback(device, DeviceInputCallback, device);
                            MacNative.IOHIDDeviceScheduleWithRunLoop(device, runLoop, defaultLoopMode);
                            return;
                        }
                        index++;
                    }
                }
                MacNative.IOHIDDeviceClose(device, IntPtr.Zero);
            }
        }
예제 #2
0
 private static void DeviceRemoved(System.IntPtr context, System.IntPtr res, System.IntPtr sender, System.IntPtr device)
 {
     foreach (Engine.Joystick joystick in engine.joysticks)
     {
         if (joystick != null)
         {
             if (joystick.id == device.ToInt64())
             {
                 engine.joysticks [joystick.index] = null;
                 MacNative.IOHIDDeviceRegisterInputValueCallback(device, IntPtr.Zero, IntPtr.Zero);
                 MacNative.IOHIDDeviceUnscheduleFromRunLoop(device, runLoop, defaultLoopMode);
                 MacNative.IOHIDDeviceClose(device, IntPtr.Zero);
                 return;
             }
         }
     }
 }