/// <summary> /// Query the devices if the input is disabled /// </summary> /// <param name="input">The input command</param> /// <returns>True if disabled input</returns> static public bool IsDisabledInput(string input) { bool disabledInput = false; disabledInput = DeviceCls.IsDisabledInput(input); // generic if (disabledInput) { return(disabledInput); } disabledInput = JoystickCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = GamepadCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = KeyboardCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = MouseCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } // others.. return(disabledInput); }
/// <summary> /// Try to derive the device class from the devInput string (mo1_, kb1_, xi1_, jsN_) /// </summary> /// <param name="devInput">The input command string dev_input format</param> /// <returns>A proper DeviceClass string</returns> static public string DeviceClassFromInput(string devInput) { string deviceClass = DeviceCls.DeviceClass; deviceClass = JoystickCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = GamepadCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = KeyboardCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = MouseCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } // others.. return(deviceClass); }
/// <summary> /// Read an action from XML - do some sanity checks /// </summary> /// <param name="xml">the XML action fragment</param> /// <returns>True if an action was decoded</returns> public bool fromXML(XElement actionNode) { ActionName = (string)actionNode.Attribute("name"); // mandadory foreach (XElement bindingNode in actionNode.Nodes( )) { string binding = bindingNode.Name.ToString( ); string input = "", actModeName = "", multi = ""; input = (string)bindingNode.Attribute("input"); // mandadory if (string.IsNullOrEmpty(input)) { input = ""; } actModeName = (string)bindingNode.Attribute("ActivationMode"); multi = (string)bindingNode.Attribute("multiTap"); string device = (string)bindingNode.Attribute("device"); //process input = DeviceCls.fromXML(input); // move from external to internal blend if (!string.IsNullOrEmpty(device)) { // AC1 style - need to reformat mouse and keyboard according to AC2 style now if (KeyboardCls.IsDeviceClass(device)) { input = KeyboardCls.FromAC1(input); } else if (MouseCls.IsDeviceClass(device)) { input = MouseCls.FromAC1(input); } else if (GamepadCls.IsDeviceClass(device)) { input = GamepadCls.FromAC1(input); } } Device = Act.DeviceClassFromInput(input); ActivationMode actMode = null; if (!string.IsNullOrEmpty(actModeName)) { actMode = ActivationModes.Instance.ActivationModeByName(actModeName); // should be a valid ActivationMode for this action } else { actMode = new ActivationMode(ActivationMode.Default); // no specific name given, use default if (!string.IsNullOrEmpty(multi)) { actMode.MultiTap = int.Parse(multi); // modify with given multiTap } } if (binding == "rebind") { Key = Act.DevTag(Device) + ActionName; // unique id of the action ActionDevice = Act.ADevice(Device); // get the enum of the input device } AddCommand(input, actMode); }//foreach return(true); }
/// <summary> /// Extends the input to a device input if not already done /// </summary> /// <param name="input">An input</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>A valid devInput (dev_input) format</returns> static public string DevInput(string input, ActionDevice aDevice) { switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.DevInput(input)); case ActionDevice.AD_Joystick: return(JoystickCls.DevInput(input)); case ActionDevice.AD_Keyboard: return(KeyboardCls.DevInput(input)); case ActionDevice.AD_Mouse: return(MouseCls.DevInput(input)); default: return(input); } }
/// <summary> /// Return the color of a device /// </summary> /// <param name="devInput">The devinput (determine JS colors)</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>The device color</returns> static public System.Drawing.Color DeviceColor(string devInput) { // background is along the input ActionDevice aDevice = ADeviceFromInput(devInput); switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.XiColor( )); case ActionDevice.AD_Joystick: return(JoystickCls.JsNColor(JoystickCls.JSNum(devInput)));// need to know which JS case ActionDevice.AD_Keyboard: return(KeyboardCls.KbdColor( )); case ActionDevice.AD_Mouse: return(MouseCls.MouseColor( )); default: return(MyColors.UnassignedColor); } }
/// <summary> /// Read an Options from XML - do some sanity check /// </summary> /// <param name="xml">the XML action fragment</param> /// <returns>True if an action was decoded</returns> public bool fromXML(XElement options) { /* * This can be a lot of the following options * try to do our best.... * * <options type="joystick" instance="1"> * <pilot_rot_moveyaw instance="1" sensitivity="0.8" exponent="1.2" /> * </options> * * * <options type="joystick" instance="2" Product="Saitek Pro Flight X-55 Rhino Stick {22150738-0000-0000-0000-504944564944}"> * <flight> * <nonlinearity_curve> * <point in="0.1" out="0.001"/> * <point in="0.25" out="0.02"/> * <point in="0.5" out="0.1"/> * <point in="0.75" out="0.125"/> * <point in="0.85" out="0.15"/> * <point in="0.90" out="0.175"/> * <point in="0.925" out="0.25"/> * <point in="0.94" out="0.45"/> * <point in="0.95" out="0.75"/> * </nonlinearity_curve> * </flight> * </options> * */ string instance = (string)options.Attribute("instance"); // mandadory string type = (string)options.Attribute("type"); // mandadory if (!int.TryParse(instance, out int nInstance)) { nInstance = 0; // get the one from the map if given (else it's a map error...) } string productS = (string)options.Attribute("Product"); // optional 3.5 ?? string devClass = DeviceCls.DeviceClass; // the generic one if (!string.IsNullOrEmpty(type)) { devClass = type; // get the one from the map if given (else it's a map error...) } // mouse arrives as type keyboard - fix it to deviceClass mouse here if (KeyboardCls.IsDeviceClass(devClass)) { devClass = MouseCls.DeviceClass; } // check if the profile contains the one we found in the map - then parse the element foreach (XElement item in options.Elements( )) { if (m_profileOptions.Contains(new ProfileOptionRec( ) { DeviceClass = devClass, OptName = item.Name.LocalName })) { m_tuning[item.Name.LocalName].Options_fromXML(item, devClass, int.Parse(instance)); } } return(true); }
/// <summary> /// Read an Options from XML - do some sanity check /// </summary> /// <param name="xml">the XML action fragment</param> /// <returns>True if an action was decoded</returns> public bool fromXML(XElement options) { /* * This can be a lot of the following options * try to do our best.... * * <options type="joystick" instance="1"> * .. * </options> * * * <options type="joystick" instance="1"> * .. * </options> * */ string instance = (string)options.Attribute("instance"); // mandadory string type = (string)options.Attribute("type"); // mandadory if (!int.TryParse(instance, out int nInstance)) { nInstance = 0; } // now dispatch to the instance to capture the content if (JoystickCls.IsDeviceClass(type)) { string toID = TuneOptionIDfromJsN(JoystickCls.DeviceClass, nInstance); // now this might not be availabe if devices have been changed if (this.ContainsKey(toID)) { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - joystick instance {0} is not available - dropped this content", nInstance); } } else if (GamepadCls.IsDeviceClass(type)) { string toID = TuneOptionID(GamepadCls.DeviceClass, nInstance); if (this.ContainsKey(toID))// 20170513: bugfix if gamepad is in the XML but not connected right now - ignore { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - xboxpad instance {0} is not available - dropped this content", nInstance); } } else if (KeyboardCls.IsDeviceClass(type)) // CIG names mouse - keyboard { string toID = TuneOptionID(MouseCls.DeviceClass, nInstance); if (this.ContainsKey(toID)) { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - keyboard(mouse) instance {0} is not available - dropped this content", nInstance); } } return(true); }
/// <summary> /// Aquire the DInput joystick devices /// </summary> /// <returns></returns> public bool InitDirectInput( ) { log.Debug( "Entry" ); // Enumerate joysticks in the system. int tabs = 0; SharpDX.XInput.UserIndex gpDeviceIndex = SharpDX.XInput.UserIndex.Any; try { // Initialize DirectInput log.Debug( "Instantiate DirectInput" ); var directInput = new DirectInput( ); log.Debug( "Get Keyboard device" ); m_Keyboard = new KeyboardCls( new Keyboard( directInput ), this ); // scan the Input for attached devices log.Debug( "Scan GameControl devices" ); int nJs = 1; // number the Joystick Tabs foreach ( DeviceInstance instance in directInput.GetDevices( DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly ) ) { log.InfoFormat( "GameControl: #{0} Type:{1} Device:{2}", tabs, instance.Type.ToString( ), instance.ProductName ); // Create the device interface log.Debug( "Create the device interface" ); SharpDX.DirectInput.Joystick jsDevice = null; SharpDX.XInput.Controller gpDevice = null; JoystickCls js = null; GamepadCls gs = null; if ( m_AppSettings.DetectGamepad && ( instance.Usage == SharpDX.Multimedia.UsageId.GenericGamepad ) ) { // detect Gamepad only if the user wishes to do so for ( SharpDX.XInput.UserIndex i = SharpDX.XInput.UserIndex.One; i < SharpDX.XInput.UserIndex.Four; i++ ) { gpDevice = new SharpDX.XInput.Controller( i ); if ( gpDevice.IsConnected ) { log.InfoFormat( "Scan Input {0} for gamepad - {1}", i, gpDevice.GetCapabilities( SharpDX.XInput.DeviceQueryType.Gamepad ).ToString( ) ); gpDeviceIndex = i; break; } } } else { jsDevice = new Joystick( directInput, instance.InstanceGuid ); log.DebugFormat( "Create the device interface for: {0}", jsDevice.Information.ProductName ); } // we have the first tab made as reference so TabPage[0] already exists if ( tabs == 0 ) { // first panel - The Tab content exists already if ( gpDevice != null ) { log.Debug( "Add first Gamepad panel" ); tc1.TabPages[tabs].Text = "Gamepad "; UC_GpadPanel uUC_GpadPanelNew = new UC_GpadPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_GpadPanelNew ); uUC_GpadPanelNew.Size = UC_JoyPanel.Size; uUC_GpadPanelNew.Location = UC_JoyPanel.Location; UC_JoyPanel.Enabled = false; UC_JoyPanel.Visible = false; // don't use this one log.Debug( "Create Gamepad instance" ); gs = new GamepadCls( gpDevice, uUC_GpadPanelNew, tabs ); // does all device related activities for that particular item gs.SetDeviceName( instance.ProductName ); tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", gs.DevName, " " ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } else { log.Debug( "Add first Joystick panel" ); log.Debug( "Create Joystick instance" ); tc1.TabPages[tabs].Text = String.Format( "Joystick {0}", nJs++ ); js = new JoystickCls( jsDevice, this, tabs + 1, UC_JoyPanel, tabs ); // does all device related activities for that particular item tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", js.DevName, js.DevInstanceGUID ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } } else { if ( gpDevice != null ) { log.Debug( "Add next Gamepad panel" ); tc1.TabPages.Add( "Gamepad " ); UC_GpadPanel uUC_GpadPanelNew = new UC_GpadPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_GpadPanelNew ); uUC_GpadPanelNew.Size = UC_JoyPanel.Size; uUC_GpadPanelNew.Location = UC_JoyPanel.Location; log.Debug( "Create Gamepad instance" ); gs = new GamepadCls( gpDevice, uUC_GpadPanelNew, tabs ); // does all device related activities for that particular item gs.SetDeviceName( instance.ProductName ); tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", gs.DevName, " " ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } else { log.Debug( "Add next Joystick panel" ); // setup the further tab contents along the reference one in TabPage[0] (the control named UC_JoyPanel) tc1.TabPages.Add( String.Format( "Joystick {0}", nJs++ ) ); UC_JoyPanel uUC_JoyPanelNew = new UC_JoyPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_JoyPanelNew ); uUC_JoyPanelNew.Size = UC_JoyPanel.Size; uUC_JoyPanelNew.Location = UC_JoyPanel.Location; log.Debug( "Create Joystick instance" ); js = new JoystickCls( jsDevice, this, tabs + 1, uUC_JoyPanelNew, tabs ); // does all device related activities for that particular item tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", js.DevName, js.DevInstanceGUID ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } } if ( gpDevice != null ) { m_Gamepad = gs; SetGamepadTab( tc1.TabPages[tabs] ); // indicates the gamepad tab (murks..) MyColors.GamepadColor = MyColors.TabColor[tabs]; // save it for future use } else if ( js != null ) { m_Joystick.Add( js ); // add to joystick list tc1.TabPages[tabs].Tag = ( m_Joystick.Count - 1 ); // used to find the tab for polling } tc1.TabPages[tabs].BackColor = MyColors.TabColor[tabs]; // each tab has its own color // next tab tabs++; if ( tabs >= JoystickCls.JSnum_MAX ) break; // cannot load more JSticks than predefined Tabs } log.DebugFormat( "Added {0} GameControl devices", tabs ); if ( tabs == 0 ) { log.Warn( "Unable to find and/or create any joystick devices." ); MessageBox.Show( "Unable to create a joystick device. Program will exit.", "No joystick found", MessageBoxButtons.OK, MessageBoxIcon.Information ); return false; } // load the profile items from the XML log.Debug( "Init ActionTree" ); InitActionTree( true ); } catch ( Exception ex ) { log.Debug( "InitDirectInput failed unexpectedly", ex ); return false; } return true; }