2019-05-03 00:29:04 +02:00
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
|
#include "KeyChord.h"
|
|
|
|
|
|
2019-05-23 19:36:29 +02:00
|
|
|
|
#include "KeyChord.g.cpp"
|
|
|
|
|
|
2021-07-12 23:24:26 +02:00
|
|
|
|
using VirtualKeyModifiers = winrt::Windows::System::VirtualKeyModifiers;
|
|
|
|
|
|
2021-03-17 21:47:24 +01:00
|
|
|
|
namespace winrt::Microsoft::Terminal::Control::implementation
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
2021-07-21 00:34:51 +02:00
|
|
|
|
static VirtualKeyModifiers modifiersFromBooleans(bool ctrl, bool alt, bool shift, bool win)
|
2020-01-03 19:44:27 +01:00
|
|
|
|
{
|
2021-07-21 00:34:51 +02:00
|
|
|
|
VirtualKeyModifiers modifiers = VirtualKeyModifiers::None;
|
|
|
|
|
WI_SetFlagIf(modifiers, VirtualKeyModifiers::Control, ctrl);
|
|
|
|
|
WI_SetFlagIf(modifiers, VirtualKeyModifiers::Menu, alt);
|
|
|
|
|
WI_SetFlagIf(modifiers, VirtualKeyModifiers::Shift, shift);
|
|
|
|
|
WI_SetFlagIf(modifiers, VirtualKeyModifiers::Windows, win);
|
|
|
|
|
return modifiers;
|
2020-01-03 19:44:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 00:34:51 +02:00
|
|
|
|
KeyChord::KeyChord(bool ctrl, bool alt, bool shift, bool win, int32_t vkey, int32_t scanCode) noexcept :
|
2021-08-12 01:09:25 +02:00
|
|
|
|
KeyChord(modifiersFromBooleans(ctrl, alt, shift, win), vkey, scanCode)
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 00:34:51 +02:00
|
|
|
|
KeyChord::KeyChord(const VirtualKeyModifiers modifiers, int32_t vkey, int32_t scanCode) noexcept :
|
2019-05-03 00:29:04 +02:00
|
|
|
|
_modifiers{ modifiers },
|
2021-07-21 00:34:51 +02:00
|
|
|
|
_vkey{ vkey },
|
|
|
|
|
_scanCode{ scanCode }
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
2021-08-12 01:09:25 +02:00
|
|
|
|
// ActionMap needs to identify KeyChords which should "layer" (overwrite) each other.
|
|
|
|
|
// For instance win+sc(41) and win+` both specify the same KeyChord on an US keyboard layout
|
|
|
|
|
// from the perspective of a user. Either of the two should correctly overwrite the other.
|
|
|
|
|
// We can help ActionMap with this by ensuring that Vkey() is always valid.
|
|
|
|
|
if (!_vkey)
|
|
|
|
|
{
|
|
|
|
|
_vkey = MapVirtualKeyW(scanCode, MAPVK_VSC_TO_VK_EX);
|
|
|
|
|
}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 23:24:26 +02:00
|
|
|
|
VirtualKeyModifiers KeyChord::Modifiers() noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
|
|
|
|
return _modifiers;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 23:24:26 +02:00
|
|
|
|
void KeyChord::Modifiers(VirtualKeyModifiers const& value) noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
|
|
|
|
_modifiers = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
|
int32_t KeyChord::Vkey() noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
|
|
|
|
return _vkey;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
|
void KeyChord::Vkey(int32_t value) noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
|
{
|
|
|
|
|
_vkey = value;
|
|
|
|
|
}
|
2021-07-21 00:34:51 +02:00
|
|
|
|
|
|
|
|
|
int32_t KeyChord::ScanCode() noexcept
|
|
|
|
|
{
|
|
|
|
|
return _scanCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeyChord::ScanCode(int32_t value) noexcept
|
|
|
|
|
{
|
|
|
|
|
_scanCode = value;
|
|
|
|
|
}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
}
|