Files
PowerToys/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/State.cpp
Andrey Nekrasov f742d3c1c3 [KBM]Allow remapping keys and shortcuts to arbitrary unicode sequences (#29399)
* [KBM] Allow remapping keys and shortcuts to arbitrary unicode sequences

* f: spelling

* f: tests

* f: split shortcut configuration

* f: address ui layout comments

* [BugReport]Don't report personal info

* f: fix crash in KBME

* f: add missed type button

* f: fix shortcut line UI elements alignment

* f: align elements size

* f: add warning about non-mapped keys
2023-11-23 10:46:07 +00:00

76 lines
2.1 KiB
C++

#include "pch.h"
#include "State.h"
#include <optional>
// Function to get the iterator of a single key remap given the source key. Returns nullopt if it isn't remapped
std::optional<SingleKeyRemapTable::iterator> State::GetSingleKeyRemap(const DWORD& originalKey)
{
auto it = singleKeyReMap.find(originalKey);
if (it != singleKeyReMap.end())
{
return it;
}
return std::nullopt;
}
std::optional<std::wstring> State::GetSingleKeyToTextRemapEvent(const DWORD originalKey) const
{
if (auto it = singleKeyToTextReMap.find(originalKey); it != end(singleKeyToTextReMap))
{
return std::get<std::wstring>(it->second);
}
else
{
return std::nullopt;
}
}
bool State::CheckShortcutRemapInvoked(const std::optional<std::wstring>& appName)
{
// Assumes appName exists in the app-specific remap table
ShortcutRemapTable& currentRemapTable = appName ? appSpecificShortcutReMap[*appName] : osLevelShortcutReMap;
for (auto& it : currentRemapTable)
{
if (it.second.isShortcutInvoked)
{
return true;
}
}
return false;
}
// Function to get the source and target of a shortcut remap given the source shortcut. Returns nullopt if it isn't remapped
ShortcutRemapTable& State::GetShortcutRemapTable(const std::optional<std::wstring>& appName)
{
if (appName)
{
auto itTable = appSpecificShortcutReMap.find(*appName);
if (itTable != appSpecificShortcutReMap.end())
{
return itTable->second;
}
}
return osLevelShortcutReMap;
}
std::vector<Shortcut>& State::GetSortedShortcutRemapVector(const std::optional<std::wstring>& appName)
{
// Assumes appName exists in the app-specific remap table
return appName ? appSpecificShortcutReMapSortedKeys[*appName] : osLevelShortcutReMapSortedKeys;
}
// Sets the activated target application in app-specific shortcut
void State::SetActivatedApp(const std::wstring& appName)
{
activatedAppSpecificShortcutTarget = appName;
}
// Gets the activated target application in app-specific shortcut
std::wstring State::GetActivatedApp()
{
return activatedAppSpecificShortcutTarget;
}