Refactor Shortcut remaps to distinguish modifiers and action keys (#1927)

* Added unique lock mutexes for thread safety

* Fixed a bug in detect key logic

* Changed dword to word

* Added early unlock statements to fix issue with shortcut guide

* Fixed type conversion warnings

* Migrated detect shortcut window to use Shortcut class

* made changes in Apply button logic

* Revert thread safety changes

* refactored code works on the UI side

* Refactored remapping code to use new Shortcut class

* Refactored to SetKeyEvent function

* Moved function to cpp file and added more comments

* Refactored map variable and handled common Win key

* Remove debug code

* Change arguments to const references
This commit is contained in:
Arjun Balgovind
2020-04-08 09:11:58 -07:00
committed by Udit Singh
parent cf54a4919b
commit 52c12731cb
14 changed files with 1261 additions and 304 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include "Helpers.h"
#include "Shortcut.h"
#include "RemapShortcut.h"
#include <interface/lowlevel_keyboard_event_data.h>
#include <mutex>
#include <winrt/Windows.UI.Xaml.Controls.h>
@@ -28,8 +30,8 @@ private:
HWND currentUIWindow;
std::mutex currentUIWindow_mutex;
// Vector to store the shortcut detected in the detect shortcut UI window. This is used in both the backend and the UI.
std::vector<DWORD> detectedShortcut;
// Object to store the shortcut detected in the detect shortcut UI window. This is used in both the backend and the UI.
Shortcut detectedShortcut;
std::mutex detectedShortcut_mutex;
// Store detected remap key in the remap UI window. This is used in both the backend and the UI.
@@ -48,7 +50,7 @@ public:
// The map members and their mutexes are left as public since the maps are used extensively in dllmain.cpp.
// Maps which store the remappings for each of the features. The bool fields should be initalised to false. They are used to check the current state of the shortcut (i.e is that particular shortcut currently pressed down or not).
// Stores single key remappings
std::unordered_map<DWORD, WORD> singleKeyReMap;
std::unordered_map<DWORD, DWORD> singleKeyReMap;
std::mutex singleKeyReMap_mutex;
// Stores keys which need to be changed from toggle behaviour to modifier behaviour. Eg. Caps Lock
@@ -56,11 +58,11 @@ public:
std::mutex singleKeyToggleToMod_mutex;
// Stores the os level shortcut remappings
std::map<std::vector<DWORD>, std::pair<std::vector<WORD>, bool>> osLevelShortcutReMap;
std::map<Shortcut, RemapShortcut> osLevelShortcutReMap;
std::mutex osLevelShortcutReMap_mutex;
// Stores the app-specific shortcut remappings. Maps application name to the shortcut map
std::map<std::wstring, std::map<std::vector<DWORD>, std::pair<std::vector<WORD>, bool>>> appSpecificShortcutReMap;
std::map<std::wstring, std::map<Shortcut, RemapShortcut>> appSpecificShortcutReMap;
std::mutex appSpecificShortcutReMap_mutex;
// Constructor
@@ -85,10 +87,10 @@ public:
void ClearSingleKeyRemaps();
// Function to add a new single key remapping
bool AddSingleKeyRemap(const DWORD& originalKey, const WORD& newRemapKey);
bool AddSingleKeyRemap(const DWORD& originalKey, const DWORD& newRemapKey);
// Function to add a new OS level shortcut remapping
bool AddOSLevelShortcut(const std::vector<DWORD>& originalSC, const std::vector<WORD>& newSC);
bool AddOSLevelShortcut(const Shortcut& originalSC, const Shortcut& newSC);
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void ConfigureDetectShortcutUI(const TextBlock& textBlock);
@@ -103,7 +105,7 @@ public:
void UpdateDetectSingleKeyRemapUI();
// Function to return the currently detected shortcut which is displayed on the UI
std::vector<DWORD> GetDetectedShortcut();
Shortcut GetDetectedShortcut();
// Function to return the currently detected remap key which is displayed on the UI
DWORD GetDetectedSingleRemapKey();