Beispiel #1
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

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

            hidmanager = CreateHIDManager();
            RegisterHIDCallbacks(hidmanager);
        }
Beispiel #2
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

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

            hidmanager = CreateHIDManager();
            RegisterHIDCallbacks(hidmanager);
        }
Beispiel #3
0
        void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (manual)
                {
                    NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerScheduleWithRunLoop(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);

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

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

                    HandleDeviceAdded         = null;
                    HandleDeviceRemoved       = null;
                    HandleDeviceValueReceived = null;
                }
                else
                {
                    Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
                }
                disposed = true;
            }
        }
Beispiel #4
0
        void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (manual)
                {
                    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);
                    }

                    HandleDeviceAdded = null;
                    HandleDeviceRemoved = null;
                    HandleDeviceValueReceived = null;

                    if (MouseEventTap != IntPtr.Zero)
                    {
                        CF.CFRelease(MouseEventTap);
                        MouseEventTap = IntPtr.Zero;
                    }
                    if (MouseEventTapSource != IntPtr.Zero)
                    {
                        CF.CFRelease(MouseEventTapSource);
                        MouseEventTapSource = IntPtr.Zero;
                    }
                }
                else
                {
                    Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
                }
                disposed = true;
            }
        }
Beispiel #5
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();
        }
Beispiel #6
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();
        }
Beispiel #7
0
        void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (manual)
                {
                    NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);
                    NativeMethods.IOHIDManagerScheduleWithRunLoop(
                        hidmanager, IntPtr.Zero, IntPtr.Zero);

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

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

                    HandleDeviceAdded = null;
                    HandleDeviceRemoved = null;
                    HandleDeviceValueReceived = null;
                }
                else
                {
                    Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
                }
                disposed = true;
            }
        }