private void LoadInputMapConfiguration(string configPath, string defaultPath) { ConfigFile configFile = new ConfigFile(); Directory directory = new Directory(); Dictionary <string, Dictionary <string, object> > config = this.LoadConfig(configPath, defaultPath, configFile, directory); foreach (var item in config) { var action = item.Key; var value = item.Value; var deadzone = value.ContainsKey("deadzone") ? (float)value["deadzone"] : 0.5f; var gamepad = value.ContainsKey("GamePad") ? (int)value["GamePad"] : -1; var keyboard = value.ContainsKey("Keyboard") ? value["Keyboard"] as string : ""; if (action != "" && gamepad != -1 && keyboard != "") { if (!InputMap.HasAction(action)) { InputMap.AddAction(action); } var inputKey = new InputEventKey(); inputKey.Scancode = (uint)OS.FindScancodeFromString(keyboard); InputMap.ActionAddEvent(action, inputKey); var inputjoy = new InputEventJoypadButton(); inputjoy.ButtonIndex = gamepad; InputMap.ActionAddEvent(action, inputjoy); InputMap.ActionSetDeadzone(action, deadzone); } } }
private static void applyJoy(string action_name, string key) { var e = new InputEventJoypadButton(); //e.Device e.ButtonIndex = int.Parse(key); InputMap.ActionAddEvent(action_name, e); }
private void ConfigureInputJoypadButton(InputEventJoypadButton inputEventJoyButton) { if (inputEventJoyButton != null && inputEventJoyButton.Pressed && currentInputName != null && !keyboardMappingActive) { int buttonIndex = (int)inputEventJoyButton.ButtonIndex; AddInput(currentInputName, buttonIndex.ToString()); AddInput("deviceId", inputEventJoyButton.Device); SetButtonText(currentInputName); currentInputName = null; GetTree().SetInputAsHandled(); } }
private void AddControllerInputsToGameMapping() { string playerPrefix; string action; InputEventJoypadMotion iejm; InputEventJoypadButton iejb; SC.IDictionaryEnumerator it = controllerInputMapping.GetEnumerator(); Dictionary mapping; for (int i = 1; i <= playerAmount; i++) { mapping = controllerInputMapping[i.ToString()] as Dictionary; if (mapping != null && mapping.Contains("deviceId")) { playerPrefix = this.CreateString("p", i, "_"); int deviceId = int.Parse(mapping["deviceId"] as string); it = mapping.GetEnumerator(); while (it.MoveNext()) { if (!it.Entry.Key.Equals("deviceId")) { action = this.CreateString(playerPrefix, it.Entry.Key); string inputValue = it.Entry.Value as string; if (IsDirectionInput(inputValue)) { iejm = new InputEventJoypadMotion(); float[] axisData = ConvertInputcodeToJoystickAxis(inputValue); iejm.Axis = System.Convert.ToInt32(axisData[0]); iejm.AxisValue = axisData[1]; iejm.Device = deviceId; InputMap.ActionAddEvent(action, iejm); } else { iejb = new InputEventJoypadButton(); iejb.ButtonIndex = int.Parse(it.Entry.Value as string); iejb.Device = deviceId; InputMap.ActionAddEvent(action, iejb); } } } } } }
public void SetValue(string _action, int gamepad_index, string KeyboardScancode, float _deadzone) { actionLineEdit.Text = _action; gamepadButton.Text = (XBoxJoystickList)gamepad_index + ""; keyboardButton.Text = KeyboardScancode; deadzoneSpinBox.Value = _deadzone; var joy = new InputEventJoypadButton(); joy.ButtonIndex = gamepad_index; GamePad = joy; var key = new InputEventKey(); key.Scancode = (uint)OS.FindScancodeFromString(KeyboardScancode); Keyboard = key; }
public static bool Bind(string KeyName, string FunctionName) { BindingObject NewBind = new BindingObject(KeyName); bool Found = false; if (WithArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(SteelInputWithArg), false).Length > 0); WithArgMethods = new List <WithArgInfo>(); foreach (MethodInfo Method in Methods) { WithArgMethods.Add( new WithArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(SteelInputWithArg)) as SteelInputWithArg ) ); } } foreach (WithArgInfo Method in WithArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithArg = Method.Tag.Function; break; } } if (WithoutArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(SteelInputWithoutArg), false).Length > 0); WithoutArgMethods = new List <WithoutArgInfo>(); foreach (MethodInfo Method in Methods) { WithoutArgMethods.Add( new WithoutArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(SteelInputWithoutArg)) as SteelInputWithoutArg ) ); } } foreach (WithoutArgInfo Method in WithoutArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithoutArg = Method.Tag.Function; break; } } if (!Found) { Console.ThrowPrint($"The specified function '{FunctionName}' does not exist as a bindable function"); return(false); } var ButtonValue = ButtonList.Left; var AxisDirection = DIRECTION.UP; var ControllerButtonValue = JoystickList.Axis0; uint Scancode = 0; switch (KeyName) //Checks custom string literals first then assumes Scancode { case ("MouseOne"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Left; break; } case ("MouseTwo"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Right; break; } case ("MouseThree"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Middle; break; } case ("WheelUp"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelUp; break; } case ("WheelDown"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelDown; break; } case ("MouseUp"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.UP; break; } case ("MouseDown"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.DOWN; break; } case ("MouseRight"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.RIGHT; break; } case ("MouseLeft"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.LEFT; break; } case ("LeftStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("LeftStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("RightStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("RightStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("XboxA"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxA; break; } case ("XboxB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxB; break; } case ("XboxX"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxX; break; } case ("XboxY"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxY; break; } case ("XboxLB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L; break; } case ("XboxRB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R; break; } case ("XboxLT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L2; break; } case ("XboxRT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R2; break; } case ("RightStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R3; break; } case ("LeftStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L3; break; } case ("DPadUp"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadUp; break; } case ("DPadDown"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadDown; break; } case ("DPadLeft"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadLeft; break; } case ("DPadRight"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadRight; break; } case ("XboxStart"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Start; break; } case ("XboxSelect"): { // Or Select. Or Share. Or The big thing in the middle of ps4 remotes. Or -. NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Select; break; } default: { //Does not match any custom string literal must either be a Scancode or is invalid uint LocalScancode = (uint)OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = TYPE.SCANCODE; Scancode = LocalScancode; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } break; } } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind InputMap.AddAction(KeyName); switch (NewBind.Type) { case (TYPE.SCANCODE): { InputEventKey Event = new InputEventKey { Scancode = Scancode }; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEBUTTON): case (TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton { ButtonIndex = (int)ButtonValue }; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion { Axis = (int)ControllerButtonValue }; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton { ButtonIndex = (int)ControllerButtonValue }; InputMap.ActionAddEvent(KeyName, Event); break; } } if (NewBind.FuncWithArg != null) { BindingsWithArg.Add(NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); } return(true); }
public static bool Bind(string actionName, string KeyName) { string FunctionName; actionName = actionName.ToLower(); // TODO - support multiple commands with semicolon string searchname = actionName.Split(" ")[0]; KeyName = KeyName.ToLower(); var kvp = _game.Commands.List.Where(e => e.Key.ToLower() == searchname).FirstOrDefault(); CommandInfo ci = kvp.Value; FunctionName = ci.FunctionName; BindingObject NewBind = new BindingObject(actionName, KeyName); bool Found = false; if (WithArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(InputWithArg), false).Length > 0); WithArgMethods = new List <WithArgInfo>(); foreach (MethodInfo Method in Methods) { WithArgMethods.Add( new WithArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(InputWithArg)) as InputWithArg ) ); } } foreach (WithArgInfo Method in WithArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithArg = Method.Tag.Function; break; } } if (WithoutArgMethods == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(InputWithoutArg), false).Length > 0); WithoutArgMethods = new List <WithoutArgInfo>(); foreach (MethodInfo Method in Methods) { WithoutArgMethods.Add( new WithoutArgInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(InputWithoutArg)) as InputWithoutArg ) ); } } foreach (WithoutArgInfo Method in WithoutArgMethods) { if (Method.Name == FunctionName) { Found = true; NewBind.FuncWithoutArg = Method.Tag.Function; break; } } if (WithArgCommands == null) { var Methods = Assembly.GetExecutingAssembly().GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(CommandWithArg), false).Length > 0); WithArgCommands = new List <WithArgCommandInfo>(); foreach (MethodInfo Method in Methods) { WithArgCommands.Add( new WithArgCommandInfo( Method.Name, Attribute.GetCustomAttribute(Method, typeof(CommandWithArg)) as CommandWithArg ) ); } } foreach (WithArgCommandInfo Method in WithArgCommands) { if (Method.Name == FunctionName) { Found = true; NewBind.CommandWithArg = Method.Tag.Function; break; } } if (!Found) { Console.ThrowPrint($"The specified function '{FunctionName}' does not exist as a bindable function"); return(false); } var ButtonValue = ButtonList.Left; var AxisDirection = ButtonInfo.DIRECTION.UP; var ControllerButtonValue = JoystickList.Axis0; uint Scancode = 0; //Checks custom string literals first then assumes Scancode KeyType kt = null; KeyTypes.List.TryGetValue(KeyName, out kt); if (kt == null) { // scancodes uint LocalScancode = (uint)OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = ButtonInfo.TYPE.SCANCODE; Scancode = LocalScancode; } else if (KeyName == "`") // this fails on ubuntu 18.04 (scancode of 0 given back) { NewBind.Type = ButtonInfo.TYPE.SCANCODE; Scancode = 96; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } } else { NewBind.Type = kt.Type; ButtonValue = kt.ButtonValue; AxisDirection = kt.Direction; ControllerButtonValue = kt.ControllerButtonValue; } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind if (!InputMap.HasAction(actionName)) { InputMap.AddAction(actionName); } switch (NewBind.Type) { case (ButtonInfo.TYPE.SCANCODE): { InputEventKey Event = new InputEventKey { Scancode = Scancode }; InputMap.ActionAddEvent(actionName, Event); break; } case (ButtonInfo.TYPE.MOUSEBUTTON): case (ButtonInfo.TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton { ButtonIndex = (int)ButtonValue }; InputMap.ActionAddEvent(actionName, Event); break; } case (ButtonInfo.TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(actionName, Event); NewBind.AxisDirection = (ButtonInfo.DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (ButtonInfo.TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion { Axis = (int)ControllerButtonValue }; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (ButtonInfo.DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (ButtonInfo.DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (ButtonInfo.DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (ButtonInfo.DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(actionName, Event); NewBind.AxisDirection = (ButtonInfo.DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (ButtonInfo.TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton { ButtonIndex = (int)ControllerButtonValue }; InputMap.ActionAddEvent(actionName, Event); break; } } if (NewBind.FuncWithArg != null || NewBind.CommandWithArg != null) { BindingsWithArg.Add(NewBind); AddDistinctBind(BindingsWithArgDistinct, NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); AddDistinctBind(BindingsWithoutArgDistinct, NewBind); } return(true); }
public static bool Bind(string KeyName, string FunctionName) { BindingObject NewBind = new BindingObject(KeyName); //We need to check that the function exitst and either takes no args or one float arg and get the Action try //First assume it takes a float argument { Sc.ScriptState State = Scripting.ConsoleState.ContinueWithAsync($"return new Action<float>(delegate(float x) {{ {FunctionName}(x); }} );").Result; NewBind.FuncWithArg = State.ReturnValue as Action <float>; } catch //Must either not exist or has different argument requirements { try //Next we assume that it exists but without an argument { Sc.ScriptState State = Scripting.ConsoleState.ContinueWithAsync($"return new Action(delegate() {{ {FunctionName}(); }} );").Result; NewBind.FuncWithoutArg = State.ReturnValue as Action; } catch //At this point we know it either does not exist or has incompatible argument requirements { Console.ThrowPrint($"The supplied function '{FunctionName}' does not exist, does not take a single float argument, or does not take zero arguments"); return(false); } } Nullable <ButtonList> ButtonValue = null; //Making it null by default prevents a compile warning further down Nullable <DIRECTION> AxisDirection = null; //Making it null by default prevents a compile warning further down Nullable <JoystickList> ControllerButtonValue = null; // Making a new variable for Controller buttons because int Scancode = 0; switch (KeyName) //Checks custom string literals first then assumes Scancode { case ("MouseOne"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Left; break; } case ("MouseTwo"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Right; break; } case ("MouseThree"): { NewBind.Type = TYPE.MOUSEBUTTON; ButtonValue = ButtonList.Middle; break; } case ("WheelUp"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelUp; break; } case ("WheelDown"): { NewBind.Type = TYPE.MOUSEWHEEL; ButtonValue = ButtonList.WheelDown; break; } case ("MouseUp"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.UP; break; } case ("MouseDown"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.DOWN; break; } case ("MouseRight"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.RIGHT; break; } case ("MouseLeft"): { NewBind.Type = TYPE.MOUSEAXIS; AxisDirection = DIRECTION.LEFT; break; } case ("LeftStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogLy; break; } case ("LeftStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("LeftStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogLx; break; } case ("RightStickUp"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.UP; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickDown"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.DOWN; ControllerButtonValue = JoystickList.AnalogRy; break; } case ("RightStickLeft"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.LEFT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("RightStickRight"): { NewBind.Type = TYPE.CONTROLLERAXIS; AxisDirection = DIRECTION.RIGHT; ControllerButtonValue = JoystickList.AnalogRx; break; } case ("XboxA"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxA; break; } case ("XboxB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxB; break; } case ("XboxX"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxX; break; } case ("XboxY"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.XboxY; break; } case ("XboxLB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L; break; } case ("XboxRB"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R; break; } case ("XboxLT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L2; break; } case ("XboxRT"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R2; break; } case ("RightStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.R3; break; } case ("LeftStickClick"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.L3; break; } case ("DPadUp"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadUp; break; } case ("DPadDown"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadDown; break; } case ("DPadLeft"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadLeft; break; } case ("DPadRight"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.DpadRight; break; } case ("XboxStart"): { NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Start; break; } case ("XboxSelect"): { // Or Select. Or Share. Or The big thing in the middle of ps4 remotes. Or -. NewBind.Type = TYPE.CONTROLLERBUTTON; ControllerButtonValue = JoystickList.Select; break; } default: { //Does not match any custom string literal must either be a Scancode or is invalid int LocalScancode = OS.FindScancodeFromString(KeyName); if (LocalScancode != 0) { //Is a valid Scancode NewBind.Type = TYPE.SCANCODE; Scancode = LocalScancode; } else { //If not a valid Scancode then the provided key must not be a valid key Console.ThrowPrint($"The supplied key '{KeyName}' is not a valid key"); return(false); } break; } } //Now we have everything we need to setup the bind with Godot's input system //First clear any bind with the same key UnBind(KeyName); //Then add new bind InputMap.AddAction(KeyName); switch (NewBind.Type) { case (TYPE.SCANCODE): { InputEventKey Event = new InputEventKey(); Event.Scancode = Scancode; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEBUTTON): case (TYPE.MOUSEWHEEL): { InputEventMouseButton Event = new InputEventMouseButton(); Event.ButtonIndex = (int)ButtonValue; InputMap.ActionAddEvent(KeyName, Event); break; } case (TYPE.MOUSEAXIS): { InputEventMouseMotion Event = new InputEventMouseMotion(); InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERAXIS): { InputEventJoypadMotion Event = new InputEventJoypadMotion(); Event.Axis = (int)ControllerButtonValue; // Set which Joystick axis we're using switch (AxisDirection) // Set which direction on the axis we need to trigger the event { case (DIRECTION.UP): { Event.AxisValue = -1; // -1, on the Vertical axis is up break; } case (DIRECTION.LEFT): { Event.AxisValue = -1; // -1, on the Horizontal axis is left break; } case (DIRECTION.DOWN): { Event.AxisValue = 1; // 1, on the Vertical axis is down break; } case (DIRECTION.RIGHT): { Event.AxisValue = 1; // 1, on the Horizontal axis is right break; } } InputMap.ActionAddEvent(KeyName, Event); NewBind.AxisDirection = (DIRECTION)AxisDirection; //Has to cast as it is Nullable break; } case (TYPE.CONTROLLERBUTTON): { InputEventJoypadButton Event = new InputEventJoypadButton(); Event.SetButtonIndex((int)ControllerButtonValue); InputMap.ActionAddEvent(KeyName, Event); break; } } if (NewBind.FuncWithArg != null) { BindingsWithArg.Add(NewBind); } else if (NewBind.FuncWithoutArg != null) { BindingsWithoutArg.Add(NewBind); } return(true); }