Example #1
0
        public static string GetKeyText(InputKey key, bool returnPlaceholderIfNone = true)
        {
            if (key >= InputKey.D0 &&
                key <= InputKey.D9)
            {
                return(key.ToString().TrimStart('D'));
            }

            return(key switch
            {
                InputKey.None => returnPlaceholderIfNone
                                     ? TitlePlaceholder
                                     : string.Empty,
                InputKey.MouseLeftButton => Title_LeftMouseButton,
                InputKey.MouseRightButton => Title_RightMouseButton,
                InputKey.MouseScrollButton => Title_MouseScrollButton,
                InputKey.MouseExtraButton1 => Title_MouseExtraButton1,
                InputKey.MouseExtraButton2 => Title_MouseExtraButton2,
                InputKey.Space => Title_SpaceBar,
                InputKey.CapsLock => Title_CapsLock,
                InputKey.OemTilde => "~",
                InputKey.CircumflexAccent => '\u005E'.ToString(),
                InputKey.OemMinus => "-",
                InputKey.OemPlus => "+",
                InputKey.OemComma => ",",
                InputKey.OemPeriod => ".",
                InputKey.OemSemicolon => ";",
                InputKey.OemQuestion => "?",
                InputKey.OemPipe => "|",
                InputKey.OemOpenBrackets => "[",
                InputKey.OemCloseBrackets => "]",
                InputKey.PageUp => Title_PageUp,
                InputKey.PageDown => Title_PageDown,
                _ => key.ToString()
            });
Example #2
0
        public static string GetKeyText(InputKey key)
        {
            if (key >= InputKey.D0 &&
                key <= InputKey.D9)
            {
                return(key.ToString().TrimStart('D'));
            }

            switch (key)
            {
            case InputKey.None:
                return(string.Empty);

            case InputKey.MouseLeftButton:
                return(Title_LeftMouseButton);

            case InputKey.MouseRightButton:
                return(Title_RightMouseButton);

            case InputKey.MouseScrollButton:
                return(Title_MouseScrollButton);

            case InputKey.Space:
                return(Title_SpaceBar);

            case InputKey.CapsLock:
                return(Title_CapsLock);

            case InputKey.OemTilde:
                return("~");

            case InputKey.CircumflexAccent:
                return('\u005E'.ToString());

            case InputKey.OemMinus:
                return("-");

            case InputKey.OemPlus:
                return("+");

            case InputKey.OemComma:
                return(",");

            case InputKey.OemPeriod:
                return(".");

            case InputKey.OemQuestion:
                return("?");

            case InputKey.PageUp:
                return(Title_PageUp);

            case InputKey.PageDown:
                return(Title_PageDown);

            default:
                return(key.ToString());
            }
        }
        private static bool IsAlreadyBoundTtl(SavedInputKey target, InputKey inputKey, Options options,
                                              ref List <SavedInputKey> currentAssigned)
        {
            if (inputKey == SavedInputKey.Empty)
            {
                return(false);
            }

            bool newAssigned = false;

            foreach (var field in typeof(Options).GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(SavedInputKey))
                {
                    var savedInputKey = (SavedInputKey)field.GetValue(options);
                    if (target != savedInputKey && inputKey == savedInputKey.value)
                    {
                        DebugLog.Info($"Already assigned: \n" +
                                      $"\tSavedInputKey: {savedInputKey.name}-{savedInputKey.ToLocalizedString("KEYNAME")}\n" +
                                      $"\tTarget: {target.name}-{target.ToLocalizedString("KEYNAME")}\n" +
                                      $"\tInputKey: {inputKey.ToString()}");
                        currentAssigned.Add(savedInputKey);
                        newAssigned = true;
                    }
                }
            }
            return(newAssigned);
        }
        void UpdateInfo()
        {
            title.text = _key.ToString();

            keyConsole.gameObject.SetActive(false);
            remapConsole.gameObject.SetActive(false);

            keyKeyboard.text = _binder.Get(_key).ToString();

            _binding = Binding.None;
        }
Example #5
0
        private string getReadableKey(InputKey key)
        {
            if (key >= InputKey.MidiA0)
            {
                return(key.ToString().Substring("Midi".Length).Replace("Sharp", "#"));
            }

            if (key >= InputKey.FirstJoystickHatRightButton)
            {
                return($"Joystick Hat {key - InputKey.FirstJoystickHatRightButton + 1} Right");
            }
            if (key >= InputKey.FirstJoystickHatLeftButton)
            {
                return($"Joystick Hat {key - InputKey.FirstJoystickHatLeftButton + 1} Left");
            }
            if (key >= InputKey.FirstJoystickHatDownButton)
            {
                return($"Joystick Hat {key - InputKey.FirstJoystickHatDownButton + 1} Down");
            }
            if (key >= InputKey.FirstJoystickHatUpButton)
            {
                return($"Joystick Hat {key - InputKey.FirstJoystickHatUpButton + 1} Up");
            }
            if (key >= InputKey.FirstJoystickAxisPositiveButton)
            {
                return($"Joystick Axis {key - InputKey.FirstJoystickAxisPositiveButton + 1} +");
            }
            if (key >= InputKey.FirstJoystickAxisNegativeButton)
            {
                return($"Joystick Axis {key - InputKey.FirstJoystickAxisNegativeButton + 1} -");
            }
            if (key >= InputKey.FirstJoystickButton)
            {
                return($"Joystick {key - InputKey.FirstJoystickButton + 1}");
            }

            switch (key)
            {
            case InputKey.None:
                return(string.Empty);

            case InputKey.Shift:
                return("Shift");

            case InputKey.Control:
                return("Ctrl");

            case InputKey.Alt:
                return("Alt");

            case InputKey.Super:
                return("Win");

            case InputKey.Escape:
                return("Esc");

            case InputKey.BackSpace:
                return("Backsp");

            case InputKey.Insert:
                return("Ins");

            case InputKey.Delete:
                return("Del");

            case InputKey.PageUp:
                return("Pgup");

            case InputKey.PageDown:
                return("Pgdn");

            case InputKey.CapsLock:
                return("Caps");

            case InputKey.Number0:
            case InputKey.Keypad0:
                return("0");

            case InputKey.Number1:
            case InputKey.Keypad1:
                return("1");

            case InputKey.Number2:
            case InputKey.Keypad2:
                return("2");

            case InputKey.Number3:
            case InputKey.Keypad3:
                return("3");

            case InputKey.Number4:
            case InputKey.Keypad4:
                return("4");

            case InputKey.Number5:
            case InputKey.Keypad5:
                return("5");

            case InputKey.Number6:
            case InputKey.Keypad6:
                return("6");

            case InputKey.Number7:
            case InputKey.Keypad7:
                return("7");

            case InputKey.Number8:
            case InputKey.Keypad8:
                return("8");

            case InputKey.Number9:
            case InputKey.Keypad9:
                return("9");

            case InputKey.Tilde:
                return("~");

            case InputKey.Minus:
                return("Minus");

            case InputKey.Plus:
                return("Plus");

            case InputKey.BracketLeft:
                return("(");

            case InputKey.BracketRight:
                return(")");

            case InputKey.Semicolon:
                return(";");

            case InputKey.Quote:
                return("\"");

            case InputKey.Comma:
                return(",");

            case InputKey.Period:
                return(".");

            case InputKey.Slash:
                return("/");

            case InputKey.BackSlash:
            case InputKey.NonUSBackSlash:
                return("\\");

            case InputKey.Mute:
                return("Mute");

            case InputKey.VolumeDown:
                return("Vol. Down");

            case InputKey.VolumeUp:
                return("Vol. Up");

            case InputKey.Stop:
                return("Media Stop");

            case InputKey.PlayPause:
                return("Media Play");

            case InputKey.TrackNext:
                return("Media Next");

            case InputKey.TrackPrevious:
                return("Media Previous");

            case InputKey.MouseLeft:
                return("M1");

            case InputKey.MouseMiddle:
                return("M3");

            case InputKey.MouseRight:
                return("M2");

            case InputKey.ExtraMouseButton1:
                return("M4");

            case InputKey.ExtraMouseButton2:
                return("M5");

            case InputKey.ExtraMouseButton3:
                return("M6");

            case InputKey.ExtraMouseButton4:
                return("M7");

            case InputKey.ExtraMouseButton5:
                return("M8");

            case InputKey.ExtraMouseButton6:
                return("M9");

            case InputKey.ExtraMouseButton7:
                return("M10");

            case InputKey.ExtraMouseButton8:
                return("M11");

            case InputKey.ExtraMouseButton9:
                return("M12");

            case InputKey.MouseWheelDown:
                return("Wheel Down");

            case InputKey.MouseWheelUp:
                return("Wheel Up");

            default:
                return(key.ToString());
            }
        }
Example #6
0
        private string getReadableKey(InputKey key)
        {
            switch (key)
            {
            case InputKey.None:
                return(string.Empty);

            case InputKey.Shift:
                return("Shift");

            case InputKey.Control:
                return("Ctrl");

            case InputKey.Alt:
                return("Alt");

            case InputKey.Win:
                return("Win");

            case InputKey.Escape:
                return("Esc");

            case InputKey.BackSpace:
                return("Backsp");

            case InputKey.Insert:
                return("Ins");

            case InputKey.Delete:
                return("Del");

            case InputKey.PageUp:
                return("Pgup");

            case InputKey.PageDown:
                return("Pgdn");

            case InputKey.CapsLock:
                return("Caps");

            case InputKey.Number0:
            case InputKey.Keypad0:
                return("0");

            case InputKey.Number1:
            case InputKey.Keypad1:
                return("1");

            case InputKey.Number2:
            case InputKey.Keypad2:
                return("2");

            case InputKey.Number3:
            case InputKey.Keypad3:
                return("3");

            case InputKey.Number4:
            case InputKey.Keypad4:
                return("4");

            case InputKey.Number5:
            case InputKey.Keypad5:
                return("5");

            case InputKey.Number6:
            case InputKey.Keypad6:
                return("6");

            case InputKey.Number7:
            case InputKey.Keypad7:
                return("7");

            case InputKey.Number8:
            case InputKey.Keypad8:
                return("8");

            case InputKey.Number9:
            case InputKey.Keypad9:
                return("9");

            case InputKey.Tilde:
                return("~");

            case InputKey.Minus:
                return("-");

            case InputKey.Plus:
                return("+");

            case InputKey.BracketLeft:
                return("(");

            case InputKey.BracketRight:
                return(")");

            case InputKey.Semicolon:
                return(";");

            case InputKey.Quote:
                return("\"");

            case InputKey.Comma:
                return(",");

            case InputKey.Period:
                return(".");

            case InputKey.Slash:
                return("/");

            case InputKey.BackSlash:
            case InputKey.NonUSBackSlash:
                return("\\");

            case InputKey.MouseLeft:
                return("M1");

            case InputKey.MouseMiddle:
                return("M3");

            case InputKey.MouseRight:
                return("M2");

            case InputKey.MouseButton1:
                return("M4");

            case InputKey.MouseButton2:
                return("M5");

            case InputKey.MouseButton3:
                return("M6");

            case InputKey.MouseButton4:
                return("M7");

            case InputKey.MouseButton5:
                return("M8");

            case InputKey.MouseButton6:
                return("M9");

            case InputKey.MouseButton7:
                return("M10");

            case InputKey.MouseButton8:
                return("M11");

            case InputKey.MouseButton9:
                return("M12");

            case InputKey.MouseWheelDown:
                return("Wheel Down");

            case InputKey.MouseWheelUp:
                return("Wheel Up");

            default:
                return(key.ToString());
            }
        }
Example #7
0
        public Input ToSdlCode(InputKey key)
        {
            Input input = this[key];

            if (input == null)
            {
                return(null);
            }

            if (input.Type == "key")
            {
                return(input);
            }

            var ctrl = SdlGameControllers.GetGameController(ProductGuid);

            if (ctrl == null)
            {
                return(input);
            }

            var mapping = ctrl.Mapping;

            var sdlret = mapping.FirstOrDefault(m => m.Input.Type == input.Type && m.Input.Value == input.Value && m.Input.Id == input.Id);

            if (sdlret == null)
            {
                if (mapping.All(m => m.Axis == SDL_CONTROLLER_AXIS.INVALID))
                {
                    switch (key)
                    {
                    case InputKey.left:
                        sdlret = mapping.FirstOrDefault(m => m.Input.Type == input.Type && m.Button == SDL_CONTROLLER_BUTTON.DPAD_LEFT);
                        break;

                    case InputKey.right:
                        sdlret = mapping.FirstOrDefault(m => m.Input.Type == input.Type && m.Button == SDL_CONTROLLER_BUTTON.DPAD_RIGHT);
                        break;

                    case InputKey.up:
                        sdlret = mapping.FirstOrDefault(m => m.Input.Type == input.Type && m.Button == SDL_CONTROLLER_BUTTON.DPAD_UP);
                        break;

                    case InputKey.down:
                        sdlret = mapping.FirstOrDefault(m => m.Input.Type == input.Type && m.Button == SDL_CONTROLLER_BUTTON.DPAD_DOWN);
                        break;
                    }
                }

                if (sdlret == null)
                {
                    SimpleLogger.Instance.Warning("ToSdlCode error can't find <input name=\"" + key.ToString() + "\" type=\"" + input.Type + "\" id=\"" + input.Id + "\" value=\"" + input.Value + "\" /> in SDL2 mapping :\r\n" + ctrl.SdlBinding);
                    return(input);
                }
            }

            Input ret = new Input()
            {
                Name = input.Name
            };

            if (sdlret.Button != SDL_CONTROLLER_BUTTON.INVALID)
            {
                ret.Type  = "button";
                ret.Value = 1;
                ret.Id    = (int)sdlret.Button;
                return(ret);
            }

            if (sdlret.Axis != SDL_CONTROLLER_AXIS.INVALID)
            {
                ret.Type  = "axis";
                ret.Id    = (int)sdlret.Axis;
                ret.Value = 1;
                return(ret);
            }

            return(ToXInputCodes(key));
        }
Example #8
0
    public static string GetLongName(this InputKey key)
    {
        int intVal = (int)key;

        if ((intVal > 0x20) && (intVal < 0x7f))
        {
            // single character ascii.
            return(((char)intVal).ToString().ToUpper());
        }
        else if ((intVal >= (int)InputKey.F1) && (intVal <= (int)InputKey.F15))
        {
            return(key.ToString());
        }

        switch (key)
        {
        case InputKey.ScrollWheelUp:
            return("MWHEEL-UP");

        case InputKey.ScrollWheelDown:
            return("MWHEEL-DWN");

        case InputKey.Tab:
            return("TAB");

        case InputKey.Clear:
            return("CLEAR");

        case InputKey.Return:
            return("ENTER");

        case InputKey.Pause:
            return("PAUSE");

        case InputKey.Space:
            return("SPACE");

        case InputKey.Delete:
            return("DEL");

        case InputKey.Keypad0:
            return("KP0");

        case InputKey.Keypad1:
            return("KP1");

        case InputKey.Keypad2:
            return("KP2");

        case InputKey.Keypad3:
            return("KP3");

        case InputKey.Keypad4:
            return("KP4");

        case InputKey.Keypad5:
            return("KP5");

        case InputKey.Keypad6:
            return("KP6");

        case InputKey.Keypad7:
            return("KP7");

        case InputKey.Keypad8:
            return("KP8");

        case InputKey.Keypad9:
            return("KP9");

        case InputKey.KeypadPeriod:
            return("KP.");

        case InputKey.KeypadDivide:
            return("KP/");

        case InputKey.KeypadMultiply:
            return("KP*");

        case InputKey.KeypadMinus:
            return("KP-");

        case InputKey.KeypadPlus:
            return("KP+");

        case InputKey.KeypadEnter:
            return("KPE");

        case InputKey.KeypadEquals:
            return("KP=");

        case InputKey.UpArrow:
            return("UP ARROW");

        case InputKey.DownArrow:
            return("DOWN ARROW");

        case InputKey.RightArrow:
            return("LEFT ARROW");

        case InputKey.LeftArrow:
            return("RIGHT ARROW");

        case InputKey.Insert:
            return("INS");

        case InputKey.Home:
            return("HOME");

        case InputKey.End:
            return("END");

        case InputKey.PageUp:
            return("PAGE UP");

        case InputKey.PageDown:
            return("PAGE DOWN");

        case InputKey.Numlock:
            return("NUMLOCK");

        case InputKey.CapsLock:
            return("CAPSLOCK");

        case InputKey.ScrollLock:
            return("SCROLL");

        case InputKey.RightShift:
            return("RSHIFT");

        case InputKey.LeftShift:
            return("SHIFT");

        case InputKey.RightControl:
            return("RCTRL");

        case InputKey.LeftControl:
            return("CTRL");

        case InputKey.RightAlt:
            return("RALT");

        case InputKey.LeftAlt:
            return("ALT");

        case InputKey.RightApple:
            return("RAPPLE");

        case InputKey.LeftCommand:
            return("CMD");

        case InputKey.Help:
            return("HELP");

        case InputKey.Print:
            return("PRINT");

        case InputKey.SysReq:
            return("SYS");

        case InputKey.Break:
            return("BREAK");
        }

        return("?" + key.ToString() + "?");
    }
Example #9
0
    public static string GetShortName(this InputKey key)
    {
        int intVal = (int)key;

        if ((intVal > 0x20) && (intVal < 0x7f))
        {
            // single character ascii.
            return(((char)intVal).ToString().ToUpper());
        }
        else if ((intVal >= (int)InputKey.F1) && (intVal <= (int)InputKey.F15))
        {
            return(key.ToString());
        }

        switch (key)
        {
        case InputKey.ScrollWheelUp:
            return("MWU");

        case InputKey.ScrollWheelDown:
            return("MWD");

        case InputKey.Tab:
            return("TAB");

        case InputKey.Clear:
            return("CLR");

        case InputKey.Return:
            return("ENT");

        case InputKey.Pause:
            return("PAU");

        case InputKey.Space:
            return("SPC");

        case InputKey.Delete:
            return("DEL");

        case InputKey.Keypad0:
            return("KP0");

        case InputKey.Keypad1:
            return("KP1");

        case InputKey.Keypad2:
            return("KP2");

        case InputKey.Keypad3:
            return("KP3");

        case InputKey.Keypad4:
            return("KP4");

        case InputKey.Keypad5:
            return("KP5");

        case InputKey.Keypad6:
            return("KP6");

        case InputKey.Keypad7:
            return("KP7");

        case InputKey.Keypad8:
            return("KP8");

        case InputKey.Keypad9:
            return("KP9");

        case InputKey.KeypadPeriod:
            return("KP.");

        case InputKey.KeypadDivide:
            return("KP/");

        case InputKey.KeypadMultiply:
            return("KP*");

        case InputKey.KeypadMinus:
            return("KP-");

        case InputKey.KeypadPlus:
            return("KP+");

        case InputKey.KeypadEnter:
            return("KPE");

        case InputKey.KeypadEquals:
            return("KP=");

        case InputKey.UpArrow:
            return("UP");

        case InputKey.DownArrow:
            return("DWN");

        case InputKey.RightArrow:
            return("LFT");

        case InputKey.LeftArrow:
            return("RGT");

        case InputKey.Insert:
            return("INS");

        case InputKey.Home:
            return("HOM");

        case InputKey.End:
            return("END");

        case InputKey.PageUp:
            return("PGU");

        case InputKey.PageDown:
            return("PGD");

        case InputKey.Numlock:
            return("NUM");

        case InputKey.CapsLock:
            return("CAP");

        case InputKey.ScrollLock:
            return("SCR");

        case InputKey.RightShift:
            return("RSHFT");

        case InputKey.LeftShift:
            return("LSHFT");

        case InputKey.RightControl:
            return("RCTRL");

        case InputKey.LeftControl:
            return("LCTRL");

        case InputKey.RightAlt:
            return("RALT");

        case InputKey.LeftAlt:
            return("LALT");

        case InputKey.RightApple:
            return("RCMD");

        case InputKey.LeftCommand:
            return("LCMD");

        case InputKey.Help:
            return("HLP");

        case InputKey.Print:
            return("PRT");

        case InputKey.SysReq:
            return("SYS");

        case InputKey.Break:
            return("BRK");
        }

        return("?" + key.ToString() + "?");
    }