diff --git a/BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs b/BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs
index a04b264d..8e08aa9e 100644
--- a/BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs
+++ b/BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs
@@ -107,7 +107,7 @@ namespace BetterGenshinImpact.Core.Config
/// 特定玩法内交互操作
///
[ObservableProperty]
- private VK _interaction = VK.VK_T;
+ private VK _interactionInSomeMode = VK.VK_T;
///
/// 开启任务追踪
@@ -291,7 +291,7 @@ namespace BetterGenshinImpact.Core.Config
/// 隐藏主界面
///
[ObservableProperty]
- private VK _hideUI = VK.VK_DIVIDE;
+ private VK _hideUI = VK.VK_OEM_2;
#endregion
diff --git a/BetterGenshinImpact/View/Pages/KeyBindingsSettingsPage.xaml b/BetterGenshinImpact/View/Pages/KeyBindingsSettingsPage.xaml
index 0a08cd84..feaf5136 100644
--- a/BetterGenshinImpact/View/Pages/KeyBindingsSettingsPage.xaml
+++ b/BetterGenshinImpact/View/Pages/KeyBindingsSettingsPage.xaml
@@ -32,11 +32,11 @@
-
diff --git a/BetterGenshinImpact/ViewModel/Pages/KeyBindingsSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/KeyBindingsSettingsPageViewModel.cs
index 8879dac0..b835c497 100644
--- a/BetterGenshinImpact/ViewModel/Pages/KeyBindingsSettingsPageViewModel.cs
+++ b/BetterGenshinImpact/ViewModel/Pages/KeyBindingsSettingsPageViewModel.cs
@@ -11,6 +11,9 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;
using Wpf.Ui.Controls;
+using BetterGenshinImpact.Genshin.Settings;
+using CommunityToolkit.Mvvm.Input;
+using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.ViewModel.Pages;
@@ -195,8 +198,8 @@ public partial class KeyBindingsSettingsPageViewModel : ObservableObject, INavig
));
actionDirectory.Children.Add(new KeyBindingSettingModel(
"特定玩法内交互操作",
- nameof(_config.Interaction),
- _config.Interaction
+ nameof(_config.InteractionInSomeMode),
+ _config.InteractionInSomeMode
));
actionDirectory.Children.Add(new KeyBindingSettingModel(
"开启任务追踪",
@@ -355,4 +358,202 @@ public partial class KeyBindingsSettingsPageViewModel : ObservableObject, INavig
KeyBindingSettingModels.Add(menuDirectory);
}
+ ///
+ /// 从注册表中读取按键
+ ///
+ [RelayCommand]
+ private void FetchFromRegistry()
+ {
+ // 读取注册表
+ SettingsContainer settings = new();
+ settings.FromReg();
+
+ var keySetting = settings.OverrideController?.KeyboardMap?.ActionElementMap;
+ if (keySetting != null)
+ {
+ foreach (var item in keySetting)
+ {
+ if (item.ElementIdentifierId is ElementIdentifierId keyId)
+ {
+ // 跳过无法识别的按键
+ if (keyId.ToName() == "Unknown" || keyId.ToName() == "None")
+ {
+ continue;
+ }
+ var key = keyId.ToVK();
+ switch (item.ActionId)
+ {
+ case ActionId.MoveForwardShow:
+ _config.MoveForward = key;
+ break;
+ case ActionId.MoveBackShow:
+ _config.MoveBackward = key;
+ break;
+ case ActionId.MoveLeftShow:
+ _config.MoveLeft = key;
+ break;
+ case ActionId.MoveRightShow:
+ _config.MoveRight = key;
+ break;
+ case ActionId.WalkRun:
+ _config.SwitchToWalkOrRun = key;
+ break;
+ case ActionId.Attack:
+ _config.NormalAttack = key;
+ break;
+ case ActionId.ElementalSkill:
+ _config.ElementalSkill = key;
+ break;
+ case ActionId.ElementalBurst:
+ _config.ElementalBurst = key;
+ break;
+ case ActionId.Sprint:
+ if (key >= VK.VK_LBUTTON && key <= VK.VK_XBUTTON2)
+ {
+ _config.SprintMouse = key;
+ }
+ else
+ {
+ _config.SprintKeyboard = key;
+ }
+ break;
+ case ActionId.AimMode:
+ _config.SwitchAimingMode = key;
+ break;
+ case ActionId.Jump:
+ _config.Jump = key;
+ break;
+ case ActionId.CancelClimb:
+ _config.Drop = key;
+ break;
+ // TODO: 拾取&交互可能不正确
+ case ActionId.UseTalk:
+ _config.PickUpOrInteract = key;
+ break;
+ case ActionId.Gadget:
+ _config.QuickUseGadget = key;
+ break;
+ case ActionId.InteractionSomeModes:
+ _config.InteractionInSomeMode = key;
+ break;
+ case ActionId.Navigation:
+ _config.QuestNavigation = key;
+ break;
+ case ActionId.AbandonChallenge:
+ _config.AbandonChallenge = key;
+ break;
+ case ActionId.Char1:
+ _config.SwitchMember1 = key;
+ break;
+ case ActionId.Char2:
+ _config.SwitchMember2 = key;
+ break;
+ case ActionId.Char3:
+ _config.SwitchMember3 = key;
+ break;
+ case ActionId.Char4:
+ _config.SwitchMember4 = key;
+ break;
+ case ActionId.Char5:
+ _config.SwitchMember5 = key;
+ break;
+ case ActionId.QuickWheel:
+ _config.ShortcutWheel = key;
+ break;
+ case ActionId.Inventory:
+ _config.OpenInventory = key;
+ break;
+ case ActionId.CharacterList:
+ _config.OpenCharacterScreen = key;
+ break;
+ case ActionId.Map:
+ _config.OpenMap = key;
+ break;
+ // TODO: 派蒙界面可能不正确
+ case ActionId.MenuGamepad:
+ _config.OpenPaimonMenu = key;
+ break;
+ case ActionId.AdventurerHandbook:
+ _config.OpenAdventurerHandbook = key;
+ break;
+ case ActionId.CoOp:
+ _config.OpenCoOpScreen = key;
+ break;
+ case ActionId.Wish:
+ _config.OpenWishScreen = key;
+ break;
+ case ActionId.BattlePass:
+ _config.OpenBattlePassScreen = key;
+ break;
+ case ActionId.Events:
+ _config.OpenTheEventsMenu = key;
+ break;
+ case ActionId.PotTasks:
+ _config.OpenTheSettingsMenu = key;
+ break;
+ case ActionId.PotEdit:
+ _config.OpenTheFurnishingScreen = key;
+ break;
+ // TODO: 星之归还未找到
+ case ActionId.QuestList:
+ _config.OpenQuestMenu = key;
+ break;
+ case ActionId.NotificationDetails:
+ _config.OpenNotificationDetails = key;
+ break;
+ case ActionId.Chat:
+ _config.OpenChatScreen = key;
+ break;
+ case ActionId.EnvironmentInfo:
+ _config.OpenSpecialEnvironmentInformation = key;
+ break;
+ case ActionId.Tutorial:
+ _config.CheckTutorialDetails = key;
+ break;
+ case ActionId.ElementalSight:
+ _config.ElementalSight = key;
+ break;
+ case ActionId.ShowCursor:
+ _config.ShowCursor = key;
+ break;
+ case ActionId.PartySetup:
+ _config.OpenPartySetupScreen = key;
+ break;
+ case ActionId.Friends:
+ _config.OpenFriendsScreen = key;
+ break;
+ // TODO: 隐藏主界面未找到
+ default:
+ break;
+ }
+ }
+ }
+
+ // 重新加载按键绑定列表
+ KeyBindingSettingModels.Clear();
+ BuildKeyBindingsList();
+ var list = GetAllNonDirectoryKeyBinding(KeyBindingSettingModels);
+ foreach (var keyConfig in list)
+ {
+ keyConfig.PropertyChanged += (sender, e) =>
+ {
+ if (sender is KeyBindingSettingModel model)
+ {
+ // 使用反射更新配置文件
+ if (e.PropertyName == nameof(model.KeyValue))
+ {
+ Debug.WriteLine($"按键绑定 \"{model.ActionName}\" 变更为 {model.KeyValue}");
+
+ var pi = _config.GetType().GetProperty(model.ConfigPropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
+ if (pi != null && pi.CanWrite)
+ {
+ pi.SetValue(_config, model.KeyValue, null);
+ }
+ }
+ }
+ };
+ }
+ }
+ }
+
}