Fixed SetTerminalInputKeyboardLayout

This commit is contained in:
Leonard Hecker
2026-04-17 20:32:18 +02:00
parent 6e3bb0ead4
commit 63b6bba433
5 changed files with 19 additions and 12 deletions

View File

@@ -28,7 +28,6 @@ ALIGNRIGHT
allocing
alpc
ALTERNATENAME
alternatename
ALTF
ALTGR
ALTNUMPAD

View File

@@ -94,6 +94,11 @@ LayoutGuard& LayoutGuard::operator=(LayoutGuard&& other) noexcept
return *this;
}
LayoutGuard::operator bool() const noexcept
{
return _layout != nullptr;
}
LayoutGuard::operator HKL() const noexcept
{
return _layout;
@@ -103,6 +108,15 @@ LayoutGuard TestHook::SetTerminalInputKeyboardLayout(const wchar_t* klid)
{
THROW_HR_IF_MSG(E_UNEXPECTED, g_keyboardLayout != nullptr, "Nested layout test overrides are not supported");
// Check if the layout is installed. LoadKeyboardLayoutW silently returns the
// current active layout if the requested one is missing.
const auto keyPath = fmt::format(FMT_COMPILE(L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\{}"), klid);
wil::unique_hkey key;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyPath.c_str(), 0, KEY_READ, key.addressof()) != ERROR_SUCCESS)
{
return {};
}
const auto layout = LoadKeyboardLayoutW(klid, KLF_NOTELLSHELL);
THROW_LAST_ERROR_IF_NULL(layout);

View File

@@ -13,6 +13,7 @@ namespace TestHook
LayoutGuard(LayoutGuard&& other) noexcept;
LayoutGuard& operator=(LayoutGuard&& other) noexcept;
explicit operator bool() const noexcept;
operator HKL() const noexcept;
private:

View File

@@ -628,12 +628,8 @@ void InputTest::TerminalInputNullKeyTests()
{
using namespace std::string_view_literals;
TestHook::LayoutGuard layout;
try
{
layout = TestHook::SetTerminalInputKeyboardLayout(L"00000409"); // US English
}
catch (...)
auto layout = TestHook::SetTerminalInputKeyboardLayout(L"00000409"); // US English
if (!layout)
{
Log::Result(TestResults::Result::Skipped);
return;

View File

@@ -258,11 +258,8 @@ class KittyKeyboardProtocolTests
TEST_CLASS_SETUP(ClassSetup)
{
try
{
layout = TestHook::SetTerminalInputKeyboardLayout(L"0001040c"); // French (Standard, AZERTY)
}
catch (...)
layout = TestHook::SetTerminalInputKeyboardLayout(L"0001040c"); // French (Standard, AZERTY)
if (!layout)
{
Log::Result(TestResults::Result::Skipped);
}