mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[Kbm] Save the remaps to file[part-1] (#2184)
* Added Inital FileWatcher Implementation * Added logic to read remap from file * Added remap logic save to file * Refactor code * Moved the strings to constant file * Added logic to handle Win key * Updated filewatcher logic to avoid duplicate events * Added comments * Fix spacing * Fix spacing * Update logic to accomodate upstream merge * Added global property name for os level shortcuts * Added subkey for inprocess keys * Remove non required file * Added Changes required after merge * Fix spacing in Helper.cpp
This commit is contained in:
@@ -2,74 +2,77 @@
|
||||
#include "Helpers.h"
|
||||
#include <sstream>
|
||||
|
||||
// Function to split a wstring based on a delimiter and return a vector of split strings
|
||||
std::vector<std::wstring> splitwstring(const std::wstring& input, wchar_t delimiter)
|
||||
namespace KeyboardManagerHelper
|
||||
{
|
||||
std::wstringstream ss(input);
|
||||
std::wstring item;
|
||||
std::vector<std::wstring> splittedStrings;
|
||||
while (std::getline(ss, item, L' '))
|
||||
// Function to split a wstring based on a delimiter and return a vector of split strings
|
||||
std::vector<std::wstring> splitwstring(const std::wstring& input, wchar_t delimiter)
|
||||
{
|
||||
splittedStrings.push_back(item);
|
||||
std::wstringstream ss(input);
|
||||
std::wstring item;
|
||||
std::vector<std::wstring> splittedStrings;
|
||||
while (std::getline(ss, item, delimiter))
|
||||
{
|
||||
splittedStrings.push_back(item);
|
||||
}
|
||||
|
||||
return splittedStrings;
|
||||
}
|
||||
|
||||
// Function to return the next sibling element for an element under a stack panel
|
||||
winrt::Windows::Foundation::IInspectable getSiblingElement(winrt::Windows::Foundation::IInspectable const& element)
|
||||
{
|
||||
FrameworkElement frameworkElement = element.as<FrameworkElement>();
|
||||
StackPanel parentElement = frameworkElement.Parent().as<StackPanel>();
|
||||
uint32_t index;
|
||||
|
||||
parentElement.Children().IndexOf(frameworkElement, index);
|
||||
return parentElement.Children().GetAt(index + 1);
|
||||
}
|
||||
|
||||
// Function to check if the key is a modifier key
|
||||
bool IsModifierKey(DWORD key)
|
||||
{
|
||||
return (GetKeyType(key) != KeyType::Action);
|
||||
}
|
||||
|
||||
return splittedStrings;
|
||||
}
|
||||
|
||||
// Function to return the next sibling element for an element under a stack panel
|
||||
IInspectable getSiblingElement(IInspectable const& element)
|
||||
{
|
||||
FrameworkElement frameworkElement = element.as<FrameworkElement>();
|
||||
StackPanel parentElement = frameworkElement.Parent().as<StackPanel>();
|
||||
uint32_t index;
|
||||
|
||||
parentElement.Children().IndexOf(frameworkElement, index);
|
||||
return parentElement.Children().GetAt(index + 1);
|
||||
}
|
||||
|
||||
// Function to check if the key is a modifier key
|
||||
bool IsModifierKey(DWORD key)
|
||||
{
|
||||
return (GetKeyType(key) != KeyType::Action);
|
||||
}
|
||||
|
||||
// Function to get the type of the key
|
||||
KeyType GetKeyType(DWORD key)
|
||||
{
|
||||
switch (key)
|
||||
// Function to get the type of the key
|
||||
KeyType GetKeyType(DWORD key)
|
||||
{
|
||||
case VK_LWIN:
|
||||
case VK_RWIN:
|
||||
return KeyType::Win;
|
||||
case VK_CONTROL:
|
||||
case VK_LCONTROL:
|
||||
case VK_RCONTROL:
|
||||
return KeyType::Ctrl;
|
||||
case VK_MENU:
|
||||
case VK_LMENU:
|
||||
case VK_RMENU:
|
||||
return KeyType::Alt;
|
||||
case VK_SHIFT:
|
||||
case VK_LSHIFT:
|
||||
case VK_RSHIFT:
|
||||
return KeyType::Shift;
|
||||
default:
|
||||
return KeyType::Action;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to return if the key is an extended key which requires the use of the extended key flag
|
||||
bool isExtendedKey(DWORD key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case VK_RCONTROL:
|
||||
case VK_RMENU:
|
||||
case VK_NUMLOCK:
|
||||
case VK_SNAPSHOT:
|
||||
case VK_CANCEL:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
switch (key)
|
||||
{
|
||||
case VK_LWIN:
|
||||
case VK_RWIN:
|
||||
return KeyType::Win;
|
||||
case VK_CONTROL:
|
||||
case VK_LCONTROL:
|
||||
case VK_RCONTROL:
|
||||
return KeyType::Ctrl;
|
||||
case VK_MENU:
|
||||
case VK_LMENU:
|
||||
case VK_RMENU:
|
||||
return KeyType::Alt;
|
||||
case VK_SHIFT:
|
||||
case VK_LSHIFT:
|
||||
case VK_RSHIFT:
|
||||
return KeyType::Shift;
|
||||
default:
|
||||
return KeyType::Action;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to return if the key is an extended key which requires the use of the extended key flag
|
||||
bool isExtendedKey(DWORD key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case VK_RCONTROL:
|
||||
case VK_RMENU:
|
||||
case VK_NUMLOCK:
|
||||
case VK_SNAPSHOT:
|
||||
case VK_CANCEL:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user