Exemple #1
0
        /// <summary>
        /// Set the state of the LED of a SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
        /// </summary>
        /// <param name="hDevice">The handle of the device.</param>
        /// <param name="enable">Defines the new state of the LED.</param>
        public static void SetLED(IntPtr hDevice, bool enable = true)
        {
            string name = RawInput.GetRawInputDeviceName(hDevice);

            IntPtr hFile = FileOperations.CreateFile(name, GENERIC.READ | GENERIC.WRITE, FILE_SHARE.READ | FILE_SHARE.WRITE, IntPtr.Zero,
                                                     FileMode.OPEN_EXISTING, FILE_ATTRIBUTE.NORMAL, IntPtr.Zero);

            if (hFile != FileOperations.INVALID_HANDLE_VALUE)
            {
                uint written;
                FileOperations.WriteFile(hFile, new byte[] { 4, (byte)(enable?1:0) }, 2, out written, IntPtr.Zero);
                FileOperations.CloseHandle(hFile);
            }

            WinKernel.SetLastError(0);
        }