Exemple #1
0
 public static extern MMRESULT joyGetDevCaps(int uJoyID, ref JOYCAPS pjc, uint cbjc);
 public static extern int joyGetDevCaps(int uJoyID, ref JOYCAPS pjc, int cbjc);
Exemple #3
0
 public static extern int joyGetDevCapsA(uint uJoyID, ref JOYCAPS caps, uint size);
Exemple #4
0
 public static extern int joyGetDevCaps(int uJoyID, ref JOYCAPS pjc, int cbjc);
Exemple #5
0
 public static extern int joyGetDevCapsA(uint uJoyID, ref JOYCAPS caps, uint size);
Exemple #6
0
 public static extern Int32 joyGetDevCaps(IntPtr uJoyID, ref JOYCAPS pjc, Int32 cbjc);
Exemple #7
0
 public static extern ResultCode joyGetDevCapsA(int uJoyID, [In][Out] JOYCAPS pjc, int cbjc);
Exemple #8
0
 public static extern ResultCode joyGetDevCapsW(int uJoyID,
                                                [In, Out, MarshalAs(UnmanagedType.LPStruct)] JOYCAPS pjc,
                                                int cbjc);
Exemple #9
0
 public static extern Int32 joyGetDevCaps(UIntPtr uJoyID, ref JOYCAPS pjc, uint cbjc);
Exemple #10
0
        /// <summary>
        /// Function to retrieve a joystick name from the registry.
        /// </summary>
        /// <param name="joystickData">Joystick capability data.</param>
        /// <param name="joystickID">ID of the joystick to retrieve data for.</param>
        /// <returns>The name of the joystick.</returns>
        private static string GetJoystickName(JOYCAPS joystickData, int joystickID)
        {
            RegistryKey rootKey = null;                                 // Root registry key.
            RegistryKey lookup  = null;                                 // Look up key.
            RegistryKey nameKey = null;                                 // Name key.

            try
            {
                string defaultName = joystickData.AxisCount + "-axis, " + joystickData.ButtonCount + "-button joystick.";                       // Default name.
                rootKey = Registry.CurrentUser;

                // Get the device ID.
                lookup = rootKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\MediaResources\Joystick\" + joystickData.RegistryKey + @"\CurrentJoystickSettings");

                // Try the local machine key as a root if that lookup failed.
                if (lookup == null)
                {
                    rootKey.Close();
                    rootKey = Registry.LocalMachine;
                    lookup  = rootKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\MediaResources\Joystick\" + joystickData.RegistryKey + @"\CurrentJoystickSettings");
                }

                if (lookup != null)
                {
                    // Key name.
                    string key = lookup.GetValue("Joystick" + (joystickID + 1) + "OEMName", string.Empty).ToString();

                    // If we have no name, then build one.
                    if (string.IsNullOrWhiteSpace(key))
                    {
                        return(defaultName);
                    }

                    // Get the name.
                    nameKey =
                        rootKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\" +
                                           key);

                    return(nameKey != null?nameKey.GetValue("OEMName", defaultName).ToString() : defaultName);
                }
                else
                {
                    return(defaultName);
                }
            }
            finally
            {
                if (nameKey != null)
                {
                    nameKey.Close();
                }
                if (lookup != null)
                {
                    lookup.Close();
                }
                if (rootKey != null)
                {
                    rootKey.Close();
                }
            }
        }
Exemple #11
0
            /// <summary>
            /// Function to retrieve the joystick capabilities.
            /// </summary>
            /// <param name="joystickID">ID of the joystick.</param>
            private void GetCaps(int joystickID)
            {
                JOYCAPS caps      = default(JOYCAPS);                                                                   // Joystick capabilities.
                var     capsFlags = JoystickCapabilityFlags.None;                                                       // Extra capability flags.

                // NOTE: We have to use Marshal.SizeOf here because DirectAccess.SizeOf does -not- check data marshalling attributes
                //       when determining the size of a structure (this is a performance decision).  So, for structures that have
                //       marshalled strings and/or fixed size arrays that need marshalling attributes (like MarshalAsAttribte), then
                //		 we -must- use Marshal.SizeOf, otherwise we should use DirectAccess.SizeOf.
                int error = Win32API.joyGetDevCaps(joystickID, ref caps, Marshal.SizeOf(typeof(JOYCAPS)));

                // If the joystick is disconnected then leave.
                if (error == 0xA7)
                {
                    return;
                }

                // If it's any other error, then throw an exception.
                if (error > 0)
                {
                    throw new GorgonException(GorgonResult.CannotRead,
                                              string.Format(Resources.GORINP_RAW_CANNOT_GET_JOYSTICK_CAPS, joystickID,
                                                            error.FormatHex()));
                }

                // Gather device info.
                if ((caps.Capabilities & JoystickCaps.HasZ) == JoystickCaps.HasZ)
                {
                    capsFlags        |= JoystickCapabilityFlags.SupportsThrottle;
                    ThrottleAxisRange = new GorgonRange((int)caps.MinimumZ, (int)caps.MaximumZ);
                }
                if ((caps.Capabilities & JoystickCaps.HasRudder) == JoystickCaps.HasRudder)
                {
                    capsFlags      |= JoystickCapabilityFlags.SupportsRudder;
                    RudderAxisRange = new GorgonRange((int)caps.MinimumRudder, (int)caps.MaximumRudder);
                }
                if ((caps.Capabilities & JoystickCaps.HasPOV) == JoystickCaps.HasPOV)
                {
                    capsFlags |= JoystickCapabilityFlags.SupportsPOV;
                    if ((caps.Capabilities & JoystickCaps.POV4Directions) == JoystickCaps.POV4Directions)
                    {
                        capsFlags |= JoystickCapabilityFlags.SupportsDiscreetPOV;
                    }
                    if ((caps.Capabilities & JoystickCaps.POVContinuousDegreeBearings) == JoystickCaps.POVContinuousDegreeBearings)
                    {
                        capsFlags |= JoystickCapabilityFlags.SupportsContinuousPOV;
                    }
                }

                if ((caps.Capabilities & JoystickCaps.HasU) == JoystickCaps.HasU)
                {
                    capsFlags          |= JoystickCapabilityFlags.SupportsSecondaryXAxis;
                    SecondaryXAxisRange = new GorgonRange((int)caps.Axis5Minimum, (int)caps.Axis5Maximum);
                }

                if ((caps.Capabilities & JoystickCaps.HasV) == JoystickCaps.HasV)
                {
                    capsFlags          |= JoystickCapabilityFlags.SupportsSecondaryYAxis;
                    SecondaryYAxisRange = new GorgonRange((int)caps.Axis6Minimum, (int)caps.Axis6Maximum);
                }

                ExtraCapabilities = capsFlags;
                AxisCount         = (int)caps.AxisCount;
                ButtonCount       = (int)caps.ButtonCount;
                ManufacturerID    = caps.ManufacturerID;
                ProductID         = caps.ProductID;

                // Get primary axis ranges.  Force the range to split into halfs going from negative to positive so that 0 is our center.
                XAxisRange = new GorgonRange(-((int)caps.MaximumX / 2) - 1, ((int)caps.MaximumX / 2));
                YAxisRange = new GorgonRange(-((int)caps.MaximumY / 2) - 1, ((int)caps.MaximumY / 2));
            }