Remap Keyboard UI (dev/keyboardManager) (#1698)

* Added initial UI implementation

* Added backend logic for remap key interaction

* Added single key remap control

* Updated Edit keyboardWindow UI

* Commented out ui logic

* Fixed issue with remap window UI and uncommented the code

* Updated customdialog window foreground color

* Updated buttons foreground color

* Added info header

* Added null check for detected key

* Removed fully qualified namespaces

* updated the background color as ligtht gray
This commit is contained in:
udit3333
2020-03-27 08:38:58 -07:00
committed by Udit Singh
parent 90ddcb30bf
commit f48040a4d7
8 changed files with 392 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
// Constructor
KeyboardManagerState::KeyboardManagerState() :
uiState(KeyboardManagerUIState::Deactivated), currentUIWindow(nullptr), currentShortcutTextBlock(nullptr)
uiState(KeyboardManagerUIState::Deactivated), currentUIWindow(nullptr), currentShortcutTextBlock(nullptr), currentSingleKeyRemapTextBlock(nullptr)
{
}
@@ -46,6 +46,10 @@ void KeyboardManagerState::ResetUIState()
SetUIState(KeyboardManagerUIState::Deactivated);
currentShortcutTextBlock = nullptr;
detectedShortcut.clear();
// Reset all the single key remap stored variables.
currentSingleKeyRemapTextBlock = nullptr;
detectedRemapKey = NULL;
}
// Function to clear the OS Level shortcut remapping table
@@ -54,18 +58,36 @@ void KeyboardManagerState::ClearOSLevelShortcuts()
osLevelShortcutReMap.clear();
}
// Function to clear the Keys remapping table.
void KeyboardManagerState::ClearSingleKeyRemaps()
{
singleKeyReMap.clear();
}
// Function to add a new OS level shortcut remapping
void KeyboardManagerState::AddOSLevelShortcut(const std::vector<DWORD>& originalSC, const std::vector<WORD>& newSC)
{
osLevelShortcutReMap[originalSC] = std::make_pair(newSC, false);
}
// Function to add a new OS level shortcut remapping
void KeyboardManagerState::AddSingleKeyRemap(const DWORD& originalKey, const WORD& newRemapKey)
{
singleKeyReMap[originalKey] = newRemapKey;
}
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void KeyboardManagerState::ConfigureDetectShortcutUI(const TextBlock& textBlock)
{
currentShortcutTextBlock = textBlock;
}
// Function to set the textblock of the detect remap key UI so that it can be accessed by the hook
void KeyboardManagerState::ConfigureDetectSingleKeyRemapUI(const TextBlock& textBlock)
{
currentSingleKeyRemapTextBlock = textBlock;
}
// Function to update the detect shortcut UI based on the entered keys
void KeyboardManagerState::UpdateDetectShortcutUI()
{
@@ -82,6 +104,22 @@ void KeyboardManagerState::UpdateDetectShortcutUI()
});
}
// Function to update the detect remap key UI based on the entered key.
void KeyboardManagerState::UpdateDetectSingleKeyRemapUI()
{
if (currentSingleKeyRemapTextBlock == nullptr)
{
return;
}
hstring remapKeyString = winrt::to_hstring((unsigned int)detectedRemapKey);
// Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used.
currentSingleKeyRemapTextBlock.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [=]() {
currentSingleKeyRemapTextBlock.Text(remapKeyString);
});
}
// Function to return the currently detected shortcut which is displayed on the UI
std::vector<DWORD> KeyboardManagerState::GetDetectedShortcut()
{
@@ -91,12 +129,28 @@ std::vector<DWORD> KeyboardManagerState::GetDetectedShortcut()
return convertWStringVectorToIntegerVector<DWORD>(detectedShortcutVector);
}
// Function to return the currently detected remap key which is displayed on the UI
DWORD KeyboardManagerState::GetDetectedSingleRemapKey()
{
hstring remapKeyString = currentSingleKeyRemapTextBlock.Text();
std::wstring remapKeyWString = remapKeyString.c_str();
DWORD remapKey = NULL;
if (!remapKeyString.empty())
{
remapKey = std::stoul(remapKeyWString);
}
return remapKey;
}
// Function which can be used in HandleKeyboardHookEvent before the single key remap event to use the UI and suppress events while the remap window is active.
bool KeyboardManagerState::DetectKeyUIBackend(LowlevelKeyboardEvent* data)
bool KeyboardManagerState::DetectSingleRemapKeyUIBackend(LowlevelKeyboardEvent* data)
{
// Check if the detect key UI window has been activated
if (CheckUIState(KeyboardManagerUIState::DetectKeyWindowActivated))
if (CheckUIState(KeyboardManagerUIState::DetectSingleKeyRemapWindowActivated))
{
detectedRemapKey = data->lParam->vkCode;
UpdateDetectSingleKeyRemapUI();
// Suppress the keyboard event
return true;
}

View File

@@ -11,7 +11,7 @@ enum class KeyboardManagerUIState
// If set to this value then there is no keyboard manager window currently active that requires a hook
Deactivated,
// If set to this value then the detect key window is currently active and it requires a hook
DetectKeyWindowActivated,
DetectSingleKeyRemapWindowActivated,
// If set to this value then the detect shortcut window is currently active and it requires a hook
DetectShortcutWindowActivated
};
@@ -29,8 +29,14 @@ private:
// 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;
// Store detected remap key in the remap UI window. This is used in both the backend and the UI.
DWORD detectedRemapKey;
// Stores the UI element which is to be updated based on the remap key entered.
TextBlock currentSingleKeyRemapTextBlock;
// Stores the UI element which is to be updated based on the shortcut entered
winrt::Windows::UI::Xaml::Controls::TextBlock currentShortcutTextBlock;
TextBlock currentShortcutTextBlock;
public:
// 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).
@@ -64,20 +70,35 @@ public:
// Function to clear the OS Level shortcut remapping table
void ClearOSLevelShortcuts();
// Function to clear the Keys remapping table
void ClearSingleKeyRemaps();
// Function to add a new single key remapping
void AddSingleKeyRemap(const DWORD& originalKey, const WORD& newRemapKey);
// Function to add a new OS level shortcut remapping
void AddOSLevelShortcut(const std::vector<DWORD>& originalSC, const std::vector<WORD>& newSC);
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void ConfigureDetectShortcutUI(const winrt::Windows::UI::Xaml::Controls::TextBlock& textBlock);
void ConfigureDetectShortcutUI(const TextBlock& textBlock);
// Function to set the textblock of the detect remap key UI so that it can be accessed by the hook
void ConfigureDetectSingleKeyRemapUI(const TextBlock& textBlock);
// Function to update the detect shortcut UI based on the entered keys
void UpdateDetectShortcutUI();
// Function to update the detect remap key UI based on the entered key.
void UpdateDetectSingleKeyRemapUI();
// Function to return the currently detected shortcut which is displayed on the UI
std::vector<DWORD> GetDetectedShortcut();
// Function to return the currently detected remap key which is displayed on the UI
DWORD GetDetectedSingleRemapKey();
// Function which can be used in HandleKeyboardHookEvent before the single key remap event to use the UI and suppress events while the remap window is active.
bool DetectKeyUIBackend(LowlevelKeyboardEvent* data);
bool DetectSingleRemapKeyUIBackend(LowlevelKeyboardEvent* data);
// Function which can be used in HandleKeyboardHookEvent before the os level shortcut remap event to use the UI and suppress events while the remap window is active.
bool DetectShortcutUIBackend(LowlevelKeyboardEvent* data);