public override PadToKey SetupCustomPadToKeyMapping(PadToKey mapping) { if (string.IsNullOrEmpty(_exename)) { return(mapping); } if (Program.Controllers.Count(c => c.Config != null && c.Config.DeviceName != "Keyboard") == 0) { return(mapping); } if (mapping == null) { mapping = new PadToKeyboard.PadToKey(); } var app = new PadToKeyApp(); app.Name = _exename; PadToKeyInput mouseInput = new PadToKeyInput(); mouseInput.Name = InputKey.hotkey | InputKey.start; mouseInput.Type = PadToKeyType.Keyboard; mouseInput.Key = "(%{KILL})"; app.Input.Add(mouseInput); mapping.Applications.Add(app); return(mapping); }
private static PadToKey LoadGamePadToKeyMapping(ProcessStartInfo path, PadToKey mapping) { string filePath = SystemConfig["rom"] + (Directory.Exists(SystemConfig["rom"]) ? "\\padto.keys" : ".keys"); EvMapyKeysFile gameMapping = EvMapyKeysFile.TryLoad(filePath); if (gameMapping == null && SystemConfig["system"] != null) { var systemMapping = Path.Combine(Program.LocalPath, ".emulationstation", "padtokey", SystemConfig["system"] + ".keys"); if (!File.Exists(systemMapping)) { systemMapping = Path.Combine(Program.AppConfig.GetFullPath("padtokey"), SystemConfig["system"] + ".keys"); } if (File.Exists(systemMapping)) { gameMapping = EvMapyKeysFile.TryLoad(systemMapping); } } if (gameMapping == null || gameMapping.All(c => c == null)) { return(mapping); } PadToKeyApp app = new PadToKeyApp(); app.Name = Path.GetFileNameWithoutExtension(path.FileName).ToLower(); int controllerIndex = 0; foreach (var player in gameMapping) { if (player == null) { controllerIndex++; continue; } foreach (var action in player) { if (action.type == "mouse") { if (action.Triggers == null || action.Triggers.Length == 0) { continue; } if (action.Triggers.FirstOrDefault() == "joystick1") { PadToKeyInput mouseInput = new PadToKeyInput(); mouseInput.Name = InputKey.leftanalogleft; mouseInput.Type = PadToKeyType.Mouse; mouseInput.Code = "X"; app.Input.Add(mouseInput); mouseInput = new PadToKeyInput(); mouseInput.Name = InputKey.leftanalogup; mouseInput.Type = PadToKeyType.Mouse; mouseInput.Code = "Y"; app.Input.Add(mouseInput); } else if (action.Triggers.FirstOrDefault() == "joystick2") { PadToKeyInput mouseInput = new PadToKeyInput(); mouseInput.Name = InputKey.rightanalogleft; mouseInput.Type = PadToKeyType.Mouse; mouseInput.Code = "X"; app.Input.Add(mouseInput); mouseInput = new PadToKeyInput(); mouseInput.Name = InputKey.rightanalogup; mouseInput.Type = PadToKeyType.Mouse; mouseInput.Code = "Y"; app.Input.Add(mouseInput); } continue; } if (action.type != "key") { continue; } InputKey k; if (!Enum.TryParse <InputKey>(string.Join(", ", action.Triggers.ToArray()).ToLower(), out k)) { continue; } PadToKeyInput input = new PadToKeyInput(); input.Name = k; input.ControllerIndex = controllerIndex; foreach (var target in action.Targets) { LinuxScanCode sc; if (!Enum.TryParse <LinuxScanCode>(target.ToUpper(), out sc)) { continue; } input.SetScanCode((uint)sc); } if (input.ScanCodes.Length > 0) { app.Input.Add(input); } } controllerIndex++; } if (app.Input.Count > 0) { if (mapping == null) { mapping = new PadToKey(); } var existingApp = mapping.Applications.FirstOrDefault(a => a.Name == app.Name); if (existingApp != null) { // Merge with existing by replacing inputs foreach (var input in app.Input) { existingApp.Input.RemoveAll(i => i.Name == input.Name); existingApp.Input.Add(input); } } else { mapping.Applications.Add(app); } } return(mapping); }