mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Windows Command Palette ("CmdPal") is the next iteration of PowerToys Run. With extensibility at its core, the Command Palette is your one-stop launcher to start _anything_.
By default, CmdPal is bound to <kbd>Win+Alt+Space</kbd>.


----
This brings the current preview version of CmdPal into the upstream PowerToys repo. There are still lots of bugs to work out, but it's reached the state we're ready to start sharing it with the world. From here, we can further collaborate with the community on the features that are important, and ensuring that we've got a most robust API to enable developers to build whatever extensions they want.
Most of the built-in PT Run modules have already been ported to CmdPal's extension API. Those include:
* Installed apps
* Shell commands
* File search (powered by the indexer)
* Windows Registry search
* Web search
* Windows Terminal Profiles
* Windows Services
* Windows settings
There are a couple new extensions built-in
* You can now search for packages on `winget` and install them right from the palette. This also powers searching for extensions for the palette
* The calculator has an entirely new implementation. This is currently less feature complete than the original PT Run one - we're looking forward to updating it to be more complete for future ingestion in Windows
* "Bookmarks" allow you to save shortcuts to files, folders, and webpages as top-level commands in the palette.
We've got a bunch of other samples too, in this repo and elsewhere
### PowerToys specific notes
CmdPal will eventually graduate out of PowerToys to live as its own application, which is why it's implemented just a little differently than most other modules. Enabling CmdPal will install its `msix` package.
The CI was minorly changed to support CmdPal version numbers independent of PowerToys itself. It doesn't make sense for us to start CmdPal at v0.90, and in the future, we want to be able to rev CmdPal independently of PT itself.
Closes #3200, closes #3600, closes #7770, closes #34273, closes #36471, closes #20976, closes #14495
-----
TODOs et al
**Blocking:**
- [ ] Images and descriptions in Settings and OOBE need to be properly defined, as mentioned before
- [ ] Niels is on it
- [x] Doesn't start properly from PowerToys unless the fix PR is merged.
- https://github.com/zadjii-msft/PowerToys/pull/556 merged
- [x] I seem to lose focus a lot when I press on some limits, like between the search bar and the results.
- This is https://github.com/zadjii-msft/PowerToys/issues/427
- [x] Turned off an extension like Calculator and it was still working.
- Need to get rid of that toggle, it doesn't do anything currently
- [x] `ListViewModel.<FetchItems>` crash
- Pretty confident that was fixed in https://github.com/zadjii-msft/PowerToys/pull/553
**Not blocking / improvements:**
- Show the shortcut through settings, as mentioned before, or create a button that would open CmdPalette settings.
- When PowerToys starts, CmdPalette is always shown if enabled. That's weird when just starting PowerToys/ logging in to the computer with PowerToys auto-start activated. I think this should at least be a setting.
- Needing to double press a result for it to do the default action seems quirky. If one is already selected, I think just pressing should be enough for it to do the action.
- This is currently a setting, though we're thinking of changing the setting even more: https://github.com/zadjii-msft/PowerToys/issues/392
- There's no URI extension. Was surprised when typing a URL that it only proposed a web search.
- [x] There's no System commands extension. Was expecting to be able to quickly restart the computer by typing restart but it wasn't there.
- This is in PR https://github.com/zadjii-msft/PowerToys/pull/452
---------
Co-authored-by: joadoumie <98557455+joadoumie@users.noreply.github.com>
Co-authored-by: Jordi Adoumie <jordiadoumie@microsoft.com>
Co-authored-by: Mike Griese <zadjii@gmail.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Michael Hawker <24302614+michael-hawker@users.noreply.github.com>
Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
Co-authored-by: Seraphima <zykovas91@gmail.com>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com>
Co-authored-by: Eric Johnson <ericjohnson327@gmail.com>
Co-authored-by: Ethan Fang <ethanfang@microsoft.com>
Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Clint Rutkas <clint@rutkas.com>
231 lines
6.0 KiB
C#
231 lines
6.0 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels.Settings;
|
|
|
|
public record HotkeySettings// : ICmdLineRepresentable
|
|
{
|
|
private const int VKTAB = 0x09;
|
|
|
|
public HotkeySettings()
|
|
{
|
|
Win = false;
|
|
Ctrl = false;
|
|
Alt = false;
|
|
Shift = false;
|
|
Code = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="HotkeySettings"/> class.
|
|
/// </summary>
|
|
/// <param name="win">Should Windows key be used</param>
|
|
/// <param name="ctrl">Should Ctrl key be used</param>
|
|
/// <param name="alt">Should Alt key be used</param>
|
|
/// <param name="shift">Should Shift key be used</param>
|
|
/// <param name="code">Go to https://learn.microsoft.com/windows/win32/inputdev/virtual-key-codes to see list of v-keys</param>
|
|
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, int code)
|
|
{
|
|
Win = win;
|
|
Ctrl = ctrl;
|
|
Alt = alt;
|
|
Shift = shift;
|
|
Code = code;
|
|
}
|
|
|
|
[JsonPropertyName("win")]
|
|
public bool Win { get; set; }
|
|
|
|
[JsonPropertyName("ctrl")]
|
|
public bool Ctrl { get; set; }
|
|
|
|
[JsonPropertyName("alt")]
|
|
public bool Alt { get; set; }
|
|
|
|
[JsonPropertyName("shift")]
|
|
public bool Shift { get; set; }
|
|
|
|
[JsonPropertyName("code")]
|
|
public int Code { get; set; }
|
|
|
|
// This is currently needed for FancyZones, we need to unify these two objects
|
|
// see src\common\settings_objects.h
|
|
[JsonPropertyName("key")]
|
|
public string Key { get; set; } = string.Empty;
|
|
|
|
public override string ToString()
|
|
{
|
|
var output = new StringBuilder();
|
|
|
|
if (Win)
|
|
{
|
|
output.Append("Win + ");
|
|
}
|
|
|
|
if (Ctrl)
|
|
{
|
|
output.Append("Ctrl + ");
|
|
}
|
|
|
|
if (Alt)
|
|
{
|
|
output.Append("Alt + ");
|
|
}
|
|
|
|
if (Shift)
|
|
{
|
|
output.Append("Shift + ");
|
|
}
|
|
|
|
if (Code > 0)
|
|
{
|
|
var localKey = Helper.GetKeyName((uint)Code);
|
|
output.Append(localKey);
|
|
}
|
|
else if (output.Length >= 2)
|
|
{
|
|
output.Remove(output.Length - 2, 2);
|
|
}
|
|
|
|
return output.ToString();
|
|
}
|
|
|
|
public List<object> GetKeysList()
|
|
{
|
|
var shortcutList = new List<object>();
|
|
|
|
if (Win)
|
|
{
|
|
shortcutList.Add(92); // The Windows key or button.
|
|
}
|
|
|
|
if (Ctrl)
|
|
{
|
|
shortcutList.Add("Ctrl");
|
|
}
|
|
|
|
if (Alt)
|
|
{
|
|
shortcutList.Add("Alt");
|
|
}
|
|
|
|
if (Shift)
|
|
{
|
|
shortcutList.Add("Shift");
|
|
|
|
// shortcutList.Add(16); // The Shift key or button.
|
|
}
|
|
|
|
if (Code > 0)
|
|
{
|
|
switch (Code)
|
|
{
|
|
// https://learn.microsoft.com/uwp/api/windows.system.virtualkey?view=winrt-20348
|
|
case 38: // The Up Arrow key or button.
|
|
case 40: // The Down Arrow key or button.
|
|
case 37: // The Left Arrow key or button.
|
|
case 39: // The Right Arrow key or button.
|
|
// case 8: // The Back key or button.
|
|
// case 13: // The Enter key or button.
|
|
shortcutList.Add(Code);
|
|
break;
|
|
default:
|
|
var localKey = Helper.GetKeyName((uint)Code);
|
|
shortcutList.Add(localKey);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return shortcutList;
|
|
}
|
|
|
|
public bool IsValid()
|
|
{
|
|
return IsAccessibleShortcut() ? false : (Alt || Ctrl || Win || Shift) && Code != 0;
|
|
}
|
|
|
|
public bool IsEmpty()
|
|
{
|
|
return !Alt && !Ctrl && !Win && !Shift && Code == 0;
|
|
}
|
|
|
|
public bool IsAccessibleShortcut()
|
|
{
|
|
// Shift+Tab and Tab are accessible shortcuts
|
|
return (!Alt && !Ctrl && !Win && Shift && Code == VKTAB)
|
|
|| (!Alt && !Ctrl && !Win && !Shift && Code == VKTAB);
|
|
}
|
|
|
|
public static bool TryParseFromCmd(string cmd, out object? result)
|
|
{
|
|
bool win = false, ctrl = false, alt = false, shift = false;
|
|
var code = 0;
|
|
|
|
var parts = cmd.Split('+');
|
|
foreach (var part in parts)
|
|
{
|
|
switch (part.Trim().ToLower(CultureInfo.InvariantCulture))
|
|
{
|
|
case "win":
|
|
win = true;
|
|
break;
|
|
case "ctrl":
|
|
ctrl = true;
|
|
break;
|
|
case "alt":
|
|
alt = true;
|
|
break;
|
|
case "shift":
|
|
shift = true;
|
|
break;
|
|
default:
|
|
if (!TryParseKeyCode(part, out code))
|
|
{
|
|
result = null;
|
|
return false;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
result = new HotkeySettings(win, ctrl, alt, shift, code);
|
|
return true;
|
|
}
|
|
|
|
private static bool TryParseKeyCode(string key, out int keyCode)
|
|
{
|
|
// ASCII symbol
|
|
if (key.Length == 1 && char.IsLetterOrDigit(key[0]))
|
|
{
|
|
keyCode = char.ToUpper(key[0], CultureInfo.InvariantCulture);
|
|
return true;
|
|
}
|
|
|
|
// VK code
|
|
else if (key.Length == 4 && key.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return int.TryParse(key.AsSpan(2), NumberStyles.HexNumber, null, out keyCode);
|
|
}
|
|
|
|
// Alias
|
|
else
|
|
{
|
|
keyCode = (int)Helper.GetKeyValue(key);
|
|
return keyCode != 0;
|
|
}
|
|
}
|
|
|
|
public bool TryToCmdRepresentable(out string result)
|
|
{
|
|
result = ToString();
|
|
result = result.Replace(" ", null);
|
|
return true;
|
|
}
|
|
}
|