mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[KBM]Allow remapping keys and shortcuts to arbitrary unicode sequences (#29399)
* [KBM] Allow remapping keys and shortcuts to arbitrary unicode sequences * f: spelling * f: tests * f: split shortcut configuration * f: address ui layout comments * [BugReport]Don't report personal info * f: fix crash in KBME * f: add missed type button * f: fix shortcut line UI elements alignment * f: align elements size * f: add warning about non-mapped keys
This commit is contained in:
@@ -28,9 +28,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
ArgumentNullException.ThrowIfNull(arg);
|
||||
|
||||
// Using Ordinal comparison for internal text
|
||||
return OriginalKeys.Equals(arg.OriginalKeys, StringComparison.Ordinal) &&
|
||||
NewRemapKeys.Equals(arg.NewRemapKeys, StringComparison.Ordinal) &&
|
||||
TargetApp.Equals(arg.TargetApp, StringComparison.Ordinal);
|
||||
return string.Equals(OriginalKeys, arg.OriginalKeys, StringComparison.Ordinal) &&
|
||||
string.Equals(NewRemapKeys, arg.NewRemapKeys, StringComparison.Ordinal) &&
|
||||
string.Equals(NewRemapString, arg.NewRemapString, StringComparison.Ordinal) &&
|
||||
string.Equals(TargetApp, arg.TargetApp, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("remapKeys")]
|
||||
public RemapKeysDataModel RemapKeys { get; set; }
|
||||
|
||||
[JsonPropertyName("remapKeysToText")]
|
||||
public RemapKeysDataModel RemapKeysToText { get; set; }
|
||||
|
||||
[JsonPropertyName("remapShortcuts")]
|
||||
public ShortcutsKeyDataModel RemapShortcuts { get; set; }
|
||||
|
||||
[JsonPropertyName("remapShortcutsToText")]
|
||||
public ShortcutsKeyDataModel RemapShortcutsToText { get; set; }
|
||||
|
||||
public KeyboardManagerProfile()
|
||||
{
|
||||
RemapKeys = new RemapKeysDataModel();
|
||||
RemapKeysToText = new RemapKeysDataModel();
|
||||
|
||||
RemapShortcuts = new ShortcutsKeyDataModel();
|
||||
RemapShortcutsToText = new ShortcutsKeyDataModel();
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("newRemapKeys")]
|
||||
public string NewRemapKeys { get; set; }
|
||||
|
||||
[JsonPropertyName("unicodeText")]
|
||||
public string NewRemapString { get; set; }
|
||||
|
||||
private static List<string> MapKeys(string stringOfKeys)
|
||||
{
|
||||
return stringOfKeys
|
||||
@@ -34,7 +37,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
public List<string> GetMappedNewRemapKeys()
|
||||
{
|
||||
return MapKeys(NewRemapKeys);
|
||||
return string.IsNullOrEmpty(NewRemapString) ? MapKeys(NewRemapKeys) : new List<string> { NewRemapString };
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
|
||||
@@ -306,6 +306,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
KeyboardManagerProfile kbmProfile = GetKBMProfile();
|
||||
_kbmItem = new DashboardModuleKBMItem() { RemapKeys = kbmProfile?.RemapKeys.InProcessRemapKeys, RemapShortcuts = KeyboardManagerViewModel.CombineShortcutLists(kbmProfile?.RemapShortcuts.GlobalRemapShortcuts, kbmProfile?.RemapShortcuts.AppSpecificRemapShortcuts) };
|
||||
|
||||
_kbmItem.RemapKeys = _kbmItem.RemapKeys.Concat(kbmProfile?.RemapKeysToText.InProcessRemapKeys).ToList();
|
||||
|
||||
var shortcutsToTextRemappings = KeyboardManagerViewModel.CombineShortcutLists(kbmProfile?.RemapShortcutsToText.GlobalRemapShortcuts, kbmProfile?.RemapShortcutsToText.AppSpecificRemapShortcuts);
|
||||
|
||||
_kbmItem.RemapShortcuts = _kbmItem.RemapShortcuts.Concat(shortcutsToTextRemappings).ToList();
|
||||
|
||||
var list = new List<DashboardModuleItem>
|
||||
{
|
||||
_kbmItem,
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return _profile.RemapKeys.InProcessRemapKeys;
|
||||
return _profile.RemapKeys.InProcessRemapKeys.Concat(_profile.RemapKeysToText.InProcessRemapKeys).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -190,11 +190,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
else if (appSpecificShortcutList == null)
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = allAppsDescription }).ToList();
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, TargetApp = allAppsDescription }).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return CombineShortcutLists(_profile.RemapShortcuts.GlobalRemapShortcuts, _profile.RemapShortcuts.AppSpecificRemapShortcuts);
|
||||
return CombineShortcutLists(_profile.RemapShortcuts.GlobalRemapShortcuts, _profile.RemapShortcuts.AppSpecificRemapShortcuts).Concat(CombineShortcutLists(_profile.RemapShortcutsToText.GlobalRemapShortcuts, _profile.RemapShortcutsToText.AppSpecificRemapShortcuts)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -333,6 +333,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
if (readSuccessfully)
|
||||
{
|
||||
FilterRemapKeysList(_profile?.RemapKeys?.InProcessRemapKeys);
|
||||
FilterRemapKeysList(_profile?.RemapKeysToText?.InProcessRemapKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user