From 7a1c27dcf305e506554b1fe4f33fe7fdbcfcacdf Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 9 Jul 2025 21:45:27 -0500 Subject: [PATCH] Add hotkey shortcuts to Command Palette context menu items (#40359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adds keyboard shortcuts to Command Palette context menu items to match PowerToys Run functionality, providing users with faster access to context actions without needing to open the context menu. ## Changes Made Added `RequestedShortcut` properties to context menu items in both `UWPApplication.cs` and `Win32Program.cs`: ### Keyboard Shortcuts Implemented **UWP Applications:** - Run as Admin: `Ctrl+Shift+Enter` - Copy Path: `Ctrl+Shift+P` - Open Containing Folder: `Ctrl+Shift+E` - Open in Console: `Ctrl+Shift+C` **Win32 Programs:** - Run as Admin: `Ctrl+Shift+Enter` - Run as Different User: `Ctrl+Shift+U` - Copy Path: `Ctrl+Shift+P` - Open Containing Folder: `Ctrl+Shift+E` - Open in Console: `Ctrl+Shift+C` ## Implementation Details - Added `using Windows.System;` import to access `VirtualKey` enum - Used `KeyChordHelpers.FromModifiers()` to create keyboard shortcuts - Applied shortcuts to `CommandContextItem` objects in `GetCommands()` methods - Maintained all existing functionality while adding hotkey accessibility ### Code Example ```csharp commands.Add(new CommandContextItem( new RunAsAdminCommand(path, directory, false)) { RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter), }); ``` ## User Experience Users can now: - Select an app in Command Palette search results - Press hotkeys directly (e.g., `Ctrl+Shift+E` to open containing folder) - Access context actions without opening the context menu (`Ctrl+K`) - Enjoy the same hotkey experience as PowerToys Run This makes Command Palette faster and more consistent with PowerToys Run, addressing the user request for "having a possibility to directly trigger any of those options with hotkey from the search results." Fixes #40358. --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to start the survey. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: zadjii-msft <18356694+zadjii-msft@users.noreply.github.com> --- .../Programs/UWPApplication.cs | 21 ++++++++++++--- .../Programs/Win32Program.cs | 26 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs index 64ba6f350d..1cf4bc4463 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs @@ -12,6 +12,7 @@ using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; using Microsoft.CommandPalette.Extensions.Toolkit; +using Windows.System; using Windows.Win32; using Windows.Win32.Storage.Packaging.Appx; using PackageVersion = Microsoft.CmdPal.Ext.Apps.Programs.UWP.PackageVersion; @@ -77,14 +78,20 @@ public class UWPApplication : IProgram { commands.Add( new CommandContextItem( - new RunAsAdminCommand(UniqueIdentifier, string.Empty, true))); + new RunAsAdminCommand(UniqueIdentifier, string.Empty, true)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter), + }); // We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users. } commands.Add( new CommandContextItem( - new CopyPathCommand(Location))); + new CopyPathCommand(Location)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C), + }); commands.Add( new CommandContextItem( @@ -92,11 +99,17 @@ public class UWPApplication : IProgram { Name = Resources.open_containing_folder, Icon = new("\ue838"), - })); + }) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.E), + }); commands.Add( new CommandContextItem( - new OpenInConsoleCommand(Package.Location))); + new OpenInConsoleCommand(Package.Location)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.R), + }); return commands; } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs index 7bc13f8122..dd6bdd875d 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs @@ -22,6 +22,7 @@ using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.Win32; +using Windows.System; namespace Microsoft.CmdPal.Ext.Apps.Programs; @@ -192,20 +193,35 @@ public class Win32Program : IProgram if (AppType != ApplicationType.InternetShortcutApplication && AppType != ApplicationType.Folder && AppType != ApplicationType.GenericFile) { commands.Add(new CommandContextItem( - new RunAsAdminCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory, false))); + new RunAsAdminCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory, false)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.Enter), + }); commands.Add(new CommandContextItem( - new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory))); + new RunAsUserCommand(!string.IsNullOrEmpty(LnkFilePath) ? LnkFilePath : FullPath, ParentDirectory)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.U), + }); } commands.Add(new CommandContextItem( - new CopyPathCommand(FullPath))); + new CopyPathCommand(FullPath)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C), + }); commands.Add(new CommandContextItem( - new OpenPathCommand(ParentDirectory))); + new OpenPathCommand(ParentDirectory)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.E), + }); commands.Add(new CommandContextItem( - new OpenInConsoleCommand(ParentDirectory))); + new OpenInConsoleCommand(ParentDirectory)) + { + RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.R), + }); return commands; }