From 356cb78bba04a5a87419edec25d147979a9de73a Mon Sep 17 00:00:00 2001 From: Jeff Lord Date: Fri, 20 Oct 2023 13:57:21 -0400 Subject: [PATCH] Working, needs lots of cleanup. --- .../KeyboardManagerEditor/Resources.resx | 10 +- .../RunProgramControl.cpp | 2 +- .../common/KeyboardManagerCommon.vcxproj | 3 + .../KeyboardManagerCommon.vcxproj.filters | 9 + .../keyboardmanager/common/RUNPROGRAMSPEC.H | 165 ++++++++++ .../keyboardmanager/common/RunProgramSpec.cpp | 150 +++++++++ .../common/RunProgramSpec2.cpp | 144 ++++++++ .../keyboardmanager/common/RunProgramSpec2.h | 31 ++ src/runner/centralized_kb_hook.cpp | 310 +++++++++--------- src/runner/general_settings.cpp | 11 +- src/runner/powertoy_module.cpp | 10 +- .../Views/KeyboardManagerPage.xaml | 18 +- .../Settings.UI/Strings/en-us/Resources.resw | 12 +- 13 files changed, 695 insertions(+), 180 deletions(-) create mode 100644 src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H create mode 100644 src/modules/keyboardmanager/common/RunProgramSpec.cpp create mode 100644 src/modules/keyboardmanager/common/RunProgramSpec2.cpp create mode 100644 src/modules/keyboardmanager/common/RunProgramSpec2.h diff --git a/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx b/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx index c5bf6569ad42..7ff3dc80aa94 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx +++ b/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx @@ -146,8 +146,11 @@ Run program shortcuts - - + + + Program name + + OK @@ -169,6 +172,9 @@ Target app: + + Program: + Warning: The following keys do not have assignments: Key on a keyboard diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp index 102c6810609c..e36cdf56dfc7 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp @@ -60,7 +60,7 @@ RunProgramControl::RunProgramControl(StackPanel table, StackPanel row, const int void RunProgramControl::SetAccessibleNameForTextBox(TextBox targetAppTextBox, int rowIndex) { // To set the accessible name of the target App text box by adding the string `All Apps` if the text box is empty, if not the application name is read by narrator. - std::wstring targetAppTextBoxAccessibleName = GET_RESOURCE_STRING(IDS_AUTOMATIONPROPERTIES_ROW) + std::to_wstring(rowIndex) + L", " + GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETAPPHEADER); + std::wstring targetAppTextBoxAccessibleName = GET_RESOURCE_STRING(IDS_AUTOMATIONPROPERTIES_ROW) + std::to_wstring(rowIndex) + L", " + GET_RESOURCE_STRING(IDS_EDITRUNPROGRAMS_PROGRAMNAME); if (targetAppTextBox.Text() == L"") { targetAppTextBoxAccessibleName += GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_ALLAPPS); diff --git a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj index ebcd470c6129..2856d29f32a5 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj +++ b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj @@ -44,6 +44,7 @@ Create + @@ -56,6 +57,8 @@ + + diff --git a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj.filters b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj.filters index d1df33fa5e4b..22331db69da9 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj.filters +++ b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + @@ -65,6 +68,12 @@ Header Files + + Header Files + + + Header Files + diff --git a/src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H b/src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H new file mode 100644 index 000000000000..57faa1b06868 --- /dev/null +++ b/src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H @@ -0,0 +1,165 @@ +#pragma once +#include "ModifierKey.h" + +#include +#include +#include + + +class RunProgramSpec +{ +public: + ModifierKey winKey = ModifierKey::Disabled; + ModifierKey ctrlKey = ModifierKey::Disabled; + ModifierKey altKey = ModifierKey::Disabled; + ModifierKey shiftKey = ModifierKey::Disabled; + DWORD actionKey = {}; + + std::wstring path = L""; + std::vector keys; + + RunProgramSpec() = default; + + // Constructor to initialize Shortcut from it's virtual key code string representation. + RunProgramSpec(const std::wstring& shortcutVK); + +private: + std::vector splitwstring(const std::wstring& input, wchar_t delimiter); + + bool RunProgramSpec::SetKey(const DWORD input); +}; + +RunProgramSpec::RunProgramSpec(const std::wstring& shortcutVK) : + winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) +{ + auto _keys = splitwstring(shortcutVK, ';'); + for (auto it : _keys) + { + auto vkKeyCode = std::stoul(it); + SetKey(vkKeyCode); + } +} + +std::vector RunProgramSpec::splitwstring(const std::wstring& input, wchar_t delimiter) +{ + std::wstringstream ss(input); + std::wstring item; + std::vector splittedStrings; + while (std::getline(ss, item, delimiter)) + { + splittedStrings.push_back(item); + } + + return splittedStrings; +} + +bool RunProgramSpec::SetKey(const DWORD input) +{ + // Since there isn't a key for a common Win key we use the key code defined by us + if (input == CommonSharedConstants::VK_WIN_BOTH) + { + if (winKey == ModifierKey::Both) + { + return false; + } + winKey = ModifierKey::Both; + } + else if (input == VK_LWIN) + { + if (winKey == ModifierKey::Left) + { + return false; + } + winKey = ModifierKey::Left; + } + else if (input == VK_RWIN) + { + if (winKey == ModifierKey::Right) + { + return false; + } + winKey = ModifierKey::Right; + } + else if (input == VK_LCONTROL) + { + if (ctrlKey == ModifierKey::Left) + { + return false; + } + ctrlKey = ModifierKey::Left; + } + else if (input == VK_RCONTROL) + { + if (ctrlKey == ModifierKey::Right) + { + return false; + } + ctrlKey = ModifierKey::Right; + } + else if (input == VK_CONTROL) + { + if (ctrlKey == ModifierKey::Both) + { + return false; + } + ctrlKey = ModifierKey::Both; + } + else if (input == VK_LMENU) + { + if (altKey == ModifierKey::Left) + { + return false; + } + altKey = ModifierKey::Left; + } + else if (input == VK_RMENU) + { + if (altKey == ModifierKey::Right) + { + return false; + } + altKey = ModifierKey::Right; + } + else if (input == VK_MENU) + { + if (altKey == ModifierKey::Both) + { + return false; + } + altKey = ModifierKey::Both; + } + else if (input == VK_LSHIFT) + { + if (shiftKey == ModifierKey::Left) + { + return false; + } + shiftKey = ModifierKey::Left; + } + else if (input == VK_RSHIFT) + { + if (shiftKey == ModifierKey::Right) + { + return false; + } + shiftKey = ModifierKey::Right; + } + else if (input == VK_SHIFT) + { + if (shiftKey == ModifierKey::Both) + { + return false; + } + shiftKey = ModifierKey::Both; + } + else + { + if (actionKey == input) + { + return false; + } + actionKey = input; + } + + return true; +} diff --git a/src/modules/keyboardmanager/common/RunProgramSpec.cpp b/src/modules/keyboardmanager/common/RunProgramSpec.cpp new file mode 100644 index 000000000000..1964e29bd77b --- /dev/null +++ b/src/modules/keyboardmanager/common/RunProgramSpec.cpp @@ -0,0 +1,150 @@ +#include "pch.h" +#include "RunProgramSpec.h" + +class RunProgramSpec +{ +public: + ModifierKey winKey = ModifierKey::Disabled; + ModifierKey ctrlKey = ModifierKey::Disabled; + ModifierKey altKey = ModifierKey::Disabled; + ModifierKey shiftKey = ModifierKey::Disabled; + DWORD actionKey = {}; + + std::wstring path = L""; + std::vector keys; + + RunProgramSpec(const std::wstring& shortcutVK) : + winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) + { + auto _keys = splitwstring(shortcutVK, ';'); + for (auto it : _keys) + { + auto vkKeyCode = std::stoul(it); + SetKey(vkKeyCode); + } + } + + std::vector splitwstring(const std::wstring& input, wchar_t delimiter) + { + std::wstringstream ss(input); + std::wstring item; + std::vector splittedStrings; + while (std::getline(ss, item, delimiter)) + { + splittedStrings.push_back(item); + } + + return splittedStrings; + } + + bool SetKey(const DWORD input) + { + // Since there isn't a key for a common Win key we use the key code defined by us + if (input == CommonSharedConstants::VK_WIN_BOTH) + { + if (winKey == ModifierKey::Both) + { + return false; + } + winKey = ModifierKey::Both; + } + else if (input == VK_LWIN) + { + if (winKey == ModifierKey::Left) + { + return false; + } + winKey = ModifierKey::Left; + } + else if (input == VK_RWIN) + { + if (winKey == ModifierKey::Right) + { + return false; + } + winKey = ModifierKey::Right; + } + else if (input == VK_LCONTROL) + { + if (ctrlKey == ModifierKey::Left) + { + return false; + } + ctrlKey = ModifierKey::Left; + } + else if (input == VK_RCONTROL) + { + if (ctrlKey == ModifierKey::Right) + { + return false; + } + ctrlKey = ModifierKey::Right; + } + else if (input == VK_CONTROL) + { + if (ctrlKey == ModifierKey::Both) + { + return false; + } + ctrlKey = ModifierKey::Both; + } + else if (input == VK_LMENU) + { + if (altKey == ModifierKey::Left) + { + return false; + } + altKey = ModifierKey::Left; + } + else if (input == VK_RMENU) + { + if (altKey == ModifierKey::Right) + { + return false; + } + altKey = ModifierKey::Right; + } + else if (input == VK_MENU) + { + if (altKey == ModifierKey::Both) + { + return false; + } + altKey = ModifierKey::Both; + } + else if (input == VK_LSHIFT) + { + if (shiftKey == ModifierKey::Left) + { + return false; + } + shiftKey = ModifierKey::Left; + } + else if (input == VK_RSHIFT) + { + if (shiftKey == ModifierKey::Right) + { + return false; + } + shiftKey = ModifierKey::Right; + } + else if (input == VK_SHIFT) + { + if (shiftKey == ModifierKey::Both) + { + return false; + } + shiftKey = ModifierKey::Both; + } + else + { + if (actionKey == input) + { + return false; + } + actionKey = input; + } + + return true; + } +}; diff --git a/src/modules/keyboardmanager/common/RunProgramSpec2.cpp b/src/modules/keyboardmanager/common/RunProgramSpec2.cpp new file mode 100644 index 000000000000..23457a6f9362 --- /dev/null +++ b/src/modules/keyboardmanager/common/RunProgramSpec2.cpp @@ -0,0 +1,144 @@ +#include "pch.h" +#include "RunProgramSpec2.h" +#include +#include +#include "Helpers.h" +#include "InputInterface.h" +#include +#include + + +RunProgramSpec2::RunProgramSpec2(const std::wstring& shortcutVK) : + winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) +{ + auto _keys = splitwstring(shortcutVK, ';'); + for (auto it : _keys) + { + auto vkKeyCode = std::stoul(it); + SetKey(vkKeyCode); + } +} + +std::vector RunProgramSpec2::splitwstring(const std::wstring& input, wchar_t delimiter) +{ + std::wstringstream ss(input); + std::wstring item; + std::vector splittedStrings; + while (std::getline(ss, item, delimiter)) + { + splittedStrings.push_back(item); + } + + return splittedStrings; +} + +bool RunProgramSpec2::SetKey(const DWORD input) +{ + // Since there isn't a key for a common Win key we use the key code defined by us + if (input == CommonSharedConstants::VK_WIN_BOTH) + { + if (winKey == ModifierKey::Both) + { + return false; + } + winKey = ModifierKey::Both; + } + else if (input == VK_LWIN) + { + if (winKey == ModifierKey::Left) + { + return false; + } + winKey = ModifierKey::Left; + } + else if (input == VK_RWIN) + { + if (winKey == ModifierKey::Right) + { + return false; + } + winKey = ModifierKey::Right; + } + else if (input == VK_LCONTROL) + { + if (ctrlKey == ModifierKey::Left) + { + return false; + } + ctrlKey = ModifierKey::Left; + } + else if (input == VK_RCONTROL) + { + if (ctrlKey == ModifierKey::Right) + { + return false; + } + ctrlKey = ModifierKey::Right; + } + else if (input == VK_CONTROL) + { + if (ctrlKey == ModifierKey::Both) + { + return false; + } + ctrlKey = ModifierKey::Both; + } + else if (input == VK_LMENU) + { + if (altKey == ModifierKey::Left) + { + return false; + } + altKey = ModifierKey::Left; + } + else if (input == VK_RMENU) + { + if (altKey == ModifierKey::Right) + { + return false; + } + altKey = ModifierKey::Right; + } + else if (input == VK_MENU) + { + if (altKey == ModifierKey::Both) + { + return false; + } + altKey = ModifierKey::Both; + } + else if (input == VK_LSHIFT) + { + if (shiftKey == ModifierKey::Left) + { + return false; + } + shiftKey = ModifierKey::Left; + } + else if (input == VK_RSHIFT) + { + if (shiftKey == ModifierKey::Right) + { + return false; + } + shiftKey = ModifierKey::Right; + } + else if (input == VK_SHIFT) + { + if (shiftKey == ModifierKey::Both) + { + return false; + } + shiftKey = ModifierKey::Both; + } + else + { + if (actionKey == input) + { + return false; + } + actionKey = input; + } + + return true; +} diff --git a/src/modules/keyboardmanager/common/RunProgramSpec2.h b/src/modules/keyboardmanager/common/RunProgramSpec2.h new file mode 100644 index 000000000000..f90d75e81cef --- /dev/null +++ b/src/modules/keyboardmanager/common/RunProgramSpec2.h @@ -0,0 +1,31 @@ +#pragma once +#include "pch.h" +#include +#include +#include "Helpers.h" +#include "InputInterface.h" +#include +#include + +class RunProgramSpec2 +{ +public: + ModifierKey winKey = ModifierKey::Disabled; + ModifierKey ctrlKey = ModifierKey::Disabled; + ModifierKey altKey = ModifierKey::Disabled; + ModifierKey shiftKey = ModifierKey::Disabled; + DWORD actionKey = {}; + + std::wstring path = L""; + std::vector keys; + + RunProgramSpec2() = default; + + // Constructor to initialize Shortcut from it's virtual key code string representation. + RunProgramSpec2(const std::wstring& shortcutVK); + +private: + std::vector splitwstring(const std::wstring& input, wchar_t delimiter); + + bool RunProgramSpec2::SetKey(const DWORD input); +}; \ No newline at end of file diff --git a/src/runner/centralized_kb_hook.cpp b/src/runner/centralized_kb_hook.cpp index fee5c185e202..be0318da3518 100644 --- a/src/runner/centralized_kb_hook.cpp +++ b/src/runner/centralized_kb_hook.cpp @@ -9,6 +9,8 @@ #include #include #include +//#include +#include "modules/keyboardmanager/common/RunProgramSpec2.h" #include namespace CentralizedKeyboardHook @@ -218,156 +220,156 @@ namespace CentralizedKeyboardHook return CallNextHookEx(hHook, nCode, wParam, lParam); } - class RunProgramSpec - { - public: - ModifierKey winKey = ModifierKey::Disabled; - ModifierKey ctrlKey = ModifierKey::Disabled; - ModifierKey altKey = ModifierKey::Disabled; - ModifierKey shiftKey = ModifierKey::Disabled; - DWORD actionKey = {}; - - std::wstring path = L""; - std::vector keys; - - RunProgramSpec(const std::wstring& shortcutVK) : - winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) - { - auto _keys = splitwstring(shortcutVK, ';'); - for (auto it : _keys) - { - auto vkKeyCode = std::stoul(it); - SetKey(vkKeyCode); - } - } - - std::vector splitwstring(const std::wstring& input, wchar_t delimiter) - { - std::wstringstream ss(input); - std::wstring item; - std::vector splittedStrings; - while (std::getline(ss, item, delimiter)) - { - splittedStrings.push_back(item); - } - - return splittedStrings; - } - - bool SetKey(const DWORD input) - { - // Since there isn't a key for a common Win key we use the key code defined by us - if (input == CommonSharedConstants::VK_WIN_BOTH) - { - if (winKey == ModifierKey::Both) - { - return false; - } - winKey = ModifierKey::Both; - } - else if (input == VK_LWIN) - { - if (winKey == ModifierKey::Left) - { - return false; - } - winKey = ModifierKey::Left; - } - else if (input == VK_RWIN) - { - if (winKey == ModifierKey::Right) - { - return false; - } - winKey = ModifierKey::Right; - } - else if (input == VK_LCONTROL) - { - if (ctrlKey == ModifierKey::Left) - { - return false; - } - ctrlKey = ModifierKey::Left; - } - else if (input == VK_RCONTROL) - { - if (ctrlKey == ModifierKey::Right) - { - return false; - } - ctrlKey = ModifierKey::Right; - } - else if (input == VK_CONTROL) - { - if (ctrlKey == ModifierKey::Both) - { - return false; - } - ctrlKey = ModifierKey::Both; - } - else if (input == VK_LMENU) - { - if (altKey == ModifierKey::Left) - { - return false; - } - altKey = ModifierKey::Left; - } - else if (input == VK_RMENU) - { - if (altKey == ModifierKey::Right) - { - return false; - } - altKey = ModifierKey::Right; - } - else if (input == VK_MENU) - { - if (altKey == ModifierKey::Both) - { - return false; - } - altKey = ModifierKey::Both; - } - else if (input == VK_LSHIFT) - { - if (shiftKey == ModifierKey::Left) - { - return false; - } - shiftKey = ModifierKey::Left; - } - else if (input == VK_RSHIFT) - { - if (shiftKey == ModifierKey::Right) - { - return false; - } - shiftKey = ModifierKey::Right; - } - else if (input == VK_SHIFT) - { - if (shiftKey == ModifierKey::Both) - { - return false; - } - shiftKey = ModifierKey::Both; - } - else - { - if (actionKey == input) - { - return false; - } - actionKey = input; - } - - return true; - } - }; + //class RunProgramSpec2 + //{ + //public: + // ModifierKey winKey = ModifierKey::Disabled; + // ModifierKey ctrlKey = ModifierKey::Disabled; + // ModifierKey altKey = ModifierKey::Disabled; + // ModifierKey shiftKey = ModifierKey::Disabled; + // DWORD actionKey = {}; + + // std::wstring path = L""; + // std::vector keys; + + // RunProgramSpec2(const std::wstring& shortcutVK) : + // winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) + // { + // auto _keys = splitwstring(shortcutVK, ';'); + // for (auto it : _keys) + // { + // auto vkKeyCode = std::stoul(it); + // SetKey(vkKeyCode); + // } + // } + + // std::vector splitwstring(const std::wstring& input, wchar_t delimiter) + // { + // std::wstringstream ss(input); + // std::wstring item; + // std::vector splittedStrings; + // while (std::getline(ss, item, delimiter)) + // { + // splittedStrings.push_back(item); + // } + + // return splittedStrings; + // } + + // bool SetKey(const DWORD input) + // { + // // Since there isn't a key for a common Win key we use the key code defined by us + // if (input == CommonSharedConstants::VK_WIN_BOTH) + // { + // if (winKey == ModifierKey::Both) + // { + // return false; + // } + // winKey = ModifierKey::Both; + // } + // else if (input == VK_LWIN) + // { + // if (winKey == ModifierKey::Left) + // { + // return false; + // } + // winKey = ModifierKey::Left; + // } + // else if (input == VK_RWIN) + // { + // if (winKey == ModifierKey::Right) + // { + // return false; + // } + // winKey = ModifierKey::Right; + // } + // else if (input == VK_LCONTROL) + // { + // if (ctrlKey == ModifierKey::Left) + // { + // return false; + // } + // ctrlKey = ModifierKey::Left; + // } + // else if (input == VK_RCONTROL) + // { + // if (ctrlKey == ModifierKey::Right) + // { + // return false; + // } + // ctrlKey = ModifierKey::Right; + // } + // else if (input == VK_CONTROL) + // { + // if (ctrlKey == ModifierKey::Both) + // { + // return false; + // } + // ctrlKey = ModifierKey::Both; + // } + // else if (input == VK_LMENU) + // { + // if (altKey == ModifierKey::Left) + // { + // return false; + // } + // altKey = ModifierKey::Left; + // } + // else if (input == VK_RMENU) + // { + // if (altKey == ModifierKey::Right) + // { + // return false; + // } + // altKey = ModifierKey::Right; + // } + // else if (input == VK_MENU) + // { + // if (altKey == ModifierKey::Both) + // { + // return false; + // } + // altKey = ModifierKey::Both; + // } + // else if (input == VK_LSHIFT) + // { + // if (shiftKey == ModifierKey::Left) + // { + // return false; + // } + // shiftKey = ModifierKey::Left; + // } + // else if (input == VK_RSHIFT) + // { + // if (shiftKey == ModifierKey::Right) + // { + // return false; + // } + // shiftKey = ModifierKey::Right; + // } + // else if (input == VK_SHIFT) + // { + // if (shiftKey == ModifierKey::Both) + // { + // return false; + // } + // shiftKey = ModifierKey::Both; + // } + // else + // { + // if (actionKey == input) + // { + // return false; + // } + // actionKey = input; + // } + + // return true; + // } + //}; bool getConfigInit = false; - std::vector runProgramSpecs; + std::vector runProgramSpecs; void RefreshConfig() { @@ -407,7 +409,7 @@ namespace CentralizedKeyboardHook auto path = it.GetObjectW().GetNamedString(L"targetApp"); - auto runProgramSpec = RunProgramSpec(originalKeys.c_str()); + auto runProgramSpec = RunProgramSpec2(originalKeys.c_str()); runProgramSpec.path = path; @@ -447,9 +449,9 @@ namespace CentralizedKeyboardHook } } - bool isPartOfAnyRunProgramSpec(DWORD key) + bool isPartOfAnyRunProgramSpec2(DWORD key) { - for (RunProgramSpec runProgramSpec : runProgramSpecs) + for (RunProgramSpec2 runProgramSpec : runProgramSpecs) { if (runProgramSpec.actionKey == key) { @@ -467,7 +469,7 @@ namespace CentralizedKeyboardHook return false; } - bool isPartOfThisRunProgramSpec(RunProgramSpec runProgramSpec, DWORD key) + bool isPartOfThisRunProgramSpec2(RunProgramSpec2 runProgramSpec, DWORD key) { for (DWORD c : runProgramSpec.keys) { @@ -485,7 +487,7 @@ namespace CentralizedKeyboardHook { setupConfig(); - if (!isPartOfAnyRunProgramSpec(hotkey.key)) + if (!isPartOfAnyRunProgramSpec2(hotkey.key)) { lastKeyInChord = 0; return; @@ -496,7 +498,7 @@ namespace CentralizedKeyboardHook return; } - for (RunProgramSpec runProgramSpec : runProgramSpecs) + for (RunProgramSpec2 runProgramSpec : runProgramSpecs) { if ( (runProgramSpec.winKey == ModifierKey::Disabled || (runProgramSpec.winKey == ModifierKey::Left && hotkey.l_win)) diff --git a/src/runner/general_settings.cpp b/src/runner/general_settings.cpp index 3d9bc9245b64..389f74a34e40 100644 --- a/src/runner/general_settings.cpp +++ b/src/runner/general_settings.cpp @@ -159,14 +159,17 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save) target_enabled = gpo_rule == powertoys_gpo::gpo_rule_configured_enabled; } - if (name != L"Keyboard Manager") + if (module_inst_enabled == target_enabled) { - if (module_inst_enabled == target_enabled) + if (name == L"Keyboard Manager" && target_enabled) { - continue; + // No state change, but KBM is still enabled, sync the hotkey state with the module state, so it can be removed for disabled modules. + powertoy.add_run_program_shortcuts(); + powertoy.UpdateHotkeyEx(); } + continue; } - + if (target_enabled) { Logger::info(L"apply_general_settings: Enabling powertoy {}", name); diff --git a/src/runner/powertoy_module.cpp b/src/runner/powertoy_module.cpp index 7ddd6cd4c248..89b666c432ce 100644 --- a/src/runner/powertoy_module.cpp +++ b/src/runner/powertoy_module.cpp @@ -9,6 +9,9 @@ #include #include #include +//#include +//#include +//#include "modules/keyboardmanager/common/RunProgramSpec2.h" #include #include @@ -18,7 +21,8 @@ std::map& modules() return modules; } -class RunProgramSpec + +class RunProgramSpec2 { public: ModifierKey winKey = ModifierKey::Disabled; @@ -30,7 +34,7 @@ class RunProgramSpec std::wstring path = L""; std::vector keys; - RunProgramSpec(const std::wstring& shortcutVK) : + RunProgramSpec2(const std::wstring& shortcutVK) : winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) { auto _keys = splitwstring(shortcutVK, ';'); @@ -270,7 +274,7 @@ void PowertoyModule::add_run_program_shortcuts() auto path = it.GetObjectW().GetNamedString(L"targetApp"); - auto runProgramSpec = RunProgramSpec(originalKeys.c_str()); + auto runProgramSpec = RunProgramSpec2(originalKeys.c_str()); // auto isChord = it.GetObjectW().GetNamedBoolean(L"isChord"); hotkey.win = (runProgramSpec.winKey == ModifierKey::Left || runProgramSpec.winKey == ModifierKey::Right); diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/KeyboardManagerPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/KeyboardManagerPage.xaml index 926b27fbd506..2e20f8a7c882 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/KeyboardManagerPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/KeyboardManagerPage.xaml @@ -187,7 +187,7 @@ - - + Remap a shortcut Keyboard Manager remap shortcuts button - + + Create a global shortcut that will start a specific configured program + + + Create a shorcut to start a program + + Shortcuts Keyboard Manager remap keyboard header @@ -2333,6 +2339,10 @@ From there, simply click on one of the supported files in the File Explorer and to as in: from x to y + + Will start + as in: a will start b + Learn more about Awake Awake is a product name, do not loc