Add support for the win key in keybindings

This commit is contained in:
Mike Griese 2021-01-28 12:23:37 -06:00
parent 71f6b581e2
commit 18d1a205bb
3 changed files with 15 additions and 18 deletions

View file

@ -9,7 +9,8 @@ namespace Microsoft.Terminal.TerminalControl
None = 0x0000,
Alt = 0x0001,
Ctrl = 0x0002,
Shift = 0x0004
Shift = 0x0004,
Windows = 0x0008
};
[default_interface]

View file

@ -11,8 +11,9 @@ using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
static constexpr std::wstring_view CTRL_KEY{ L"ctrl" };
static constexpr std::wstring_view SHIFT_KEY{ L"shift" };
static constexpr std::wstring_view ALT_KEY{ L"alt" };
static constexpr std::wstring_view WIN_KEY{ L"win" };
static constexpr int MAX_CHORD_PARTS = 4;
static constexpr int MAX_CHORD_PARTS = 5; // win+ctrl+alt+shift+key
// clang-format off
static const std::unordered_map<std::wstring_view, int32_t> vkeyNamePairs {
@ -143,6 +144,10 @@ KeyChord KeyChordSerialization::FromString(const winrt::hstring& hstr)
{
modifiers |= KeyModifiers::Shift;
}
else if (lowercase == WIN_KEY)
{
modifiers |= KeyModifiers::Windows;
}
else
{
bool foundKey = false;
@ -224,6 +229,11 @@ winrt::hstring KeyChordSerialization::ToString(const KeyChord& chord)
std::wstring buffer{ L"" };
// Add modifiers
if (WI_IsFlagSet(modifiers, KeyModifiers::Windows))
{
buffer += WIN_KEY;
buffer += L"+";
}
if (WI_IsFlagSet(modifiers, KeyModifiers::Ctrl))
{
buffer += CTRL_KEY;

View file

@ -861,29 +861,15 @@ void IslandWindow::SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalCon
if (hotkey)
{
auto modifiers = hotkey.Modifiers();
// WPARAM wParam = hotkey.Vkey() |
// (WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? HOTKEYF_ALT << 8 : 0) |
// (WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? HOTKEYF_CONTROL << 8 : 0) |
// (WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? HOTKEYF_SHIFT << 8 : 0);
// auto result = SendMessage(_window.get(), WM_SETHOTKEY, wParam, 0);
// result;
// auto a = result + 1;
// a;
auto MODs = MOD_NOREPEAT |
(WI_IsFlagSet(modifiers, KeyModifiers::Windows) ? MOD_WIN : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? MOD_ALT : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? MOD_CONTROL : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? MOD_SHIFT : 0);
auto res = RegisterHotKey(_window.get(), 1, MODs, hotkey.Vkey());
LOG_LAST_ERROR_IF(!res);
// if (!res)
// {
// // auto gle = GetLastError();
// }
// res;
// auto b = !res;
// b;
}
}