private void controlSelect_SelectedIndexChanged(object sender, System.EventArgs e) { if(ffActuator != null) ffActuator.Unacquire(); feedbackAmountSlider.Enabled = false; objectGUIDValue.Enabled = false; xmlQueryButton.Enabled = false; foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.All, EnumDevicesFlags.ForceFeeback)) { if(((string)controlSelect.SelectedItem).CompareTo(di.InstanceName) == 0) { ffActuator = new Device(di.InstanceGuid); if(ffActuator == null) { throw new Exception("Cannot instantiate joystick"); } //set cooperative level. ffActuator.SetCooperativeLevel( this, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background); //Set axis mode absolute. ffActuator.Properties.AxisModeAbsolute = true; //Acquire joystick for capturing. ffActuator.Acquire(); //Configure axes foreach(DeviceObjectInstance doi in ffActuator.Objects) { //Set axes ranges. if((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { ffActuator.Properties.SetRange( ParameterHow.ById, doi.ObjectId, new InputRange(-5000,5000)); } int[] temp; // Get info about first two FF axii on the device if ((doi.Flags & (int)ObjectInstanceFlags.Actuator) != 0) { if (forceAxes != null) { temp = new int[forceAxes.Length + 1]; forceAxes.CopyTo(temp,0); forceAxes = temp; } else { forceAxes = new int[1]; } // Store the offset of each axis. forceAxes[forceAxes.Length - 1] = doi.Offset; if (forceAxes.Length == 2) { break; } string path = @"C:\temp\force.ffe"; EffectList el = null; el = ffActuator.GetEffects(path,FileEffectsFlags.ModifyIfNeeded); EffectObject feo = null; foreach(FileEffect fe in el) { constantVibrate = fe.EffectStruct; feo = new EffectObject( fe.EffectGuid, fe.EffectStruct, ffActuator); try { feo.Download(); } catch(Exception ex) { throw new Exception("Could not download force feedback effect file.", ex); } eo = feo; break; } constantVibrate.Constant.Magnitude = 0; eo.SetParameters(constantVibrate, EffectParameterFlags.TypeSpecificParams); eo.Download(); eo.Start(1); feedbackAmountSlider.Enabled = true; objectGUIDValue.Enabled = true; xmlQueryButton.Enabled = true; } } break; } } }