Removed ARM/x86 configs and minor refactors (dev/keyboardManager) (#1785)

* Removed ARM and x86 configs

* renamed files and references and localized strings
This commit is contained in:
Arjun Balgovind
2020-03-30 11:05:29 -07:00
committed by Udit Singh
parent f48040a4d7
commit 467cf919be
13 changed files with 99 additions and 211 deletions

View File

@@ -4,6 +4,7 @@
#include <interface/win_hook_event_data.h>
#include <common/settings_objects.h>
#include "trace.h"
#include "resource.h"
#include <keyboardmanager/ui/MainWindow.h>
#include <keyboardmanager/common/KeyboardManagerState.h>
@@ -26,22 +27,20 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
return TRUE;
}
// The PowerToy name that will be shown in the settings.
const static wchar_t* MODULE_NAME = L"PowerKeys";
// Add a description that will we shown in the module settings page.
const static wchar_t* MODULE_DESC = L"Customize your experience by remapping keys or creating new shortcuts!";
// Implement the PowerToy Module Interface and all the required methods.
class PowerKeys : public PowertoyModuleIface
class KeyboardManager : public PowertoyModuleIface
{
private:
// The PowerToy state.
bool m_enabled = false;
// Flags used for distinguishing key events sent by PowerKeys
static const ULONG_PTR POWERKEYS_INJECTED_FLAG = 0x1;
static const ULONG_PTR POWERKEYS_SINGLEKEY_FLAG = 0x11;
static const ULONG_PTR POWERKEYS_SHORTCUT_FLAG = 0x101;
// The PowerToy name that will be shown in the settings.
const std::wstring app_name = GET_RESOURCE_STRING(IDS_KEYBOARDMANAGER);
// Flags used for distinguishing key events sent by Keyboard Manager
static const ULONG_PTR KEYBOARDMANAGER_INJECTED_FLAG = 0x1;
static const ULONG_PTR KEYBOARDMANAGER_SINGLEKEY_FLAG = 0x11;
static const ULONG_PTR KEYBOARDMANAGER_SHORTCUT_FLAG = 0x101;
// Dummy key event used in between key up and down events to prevent certain global events from happening
static const DWORD DUMMY_KEY = 0xFF;
@@ -52,8 +51,8 @@ private:
// Required for Unhook in old versions of Windows
static HHOOK hook_handle_copy;
// Static pointer to the current powerkeys object required for accessing the HandleKeyboardHookEvent function in the hook procedure (Only global or static variables can be accessed in a hook procedure CALLBACK)
static PowerKeys* powerkeys_object_ptr;
// Static pointer to the current keyboardmanager object required for accessing the HandleKeyboardHookEvent function in the hook procedure (Only global or static variables can be accessed in a hook procedure CALLBACK)
static KeyboardManager* keyboardmanager_object_ptr;
// Variable which stores all the state information to be shared between the UI and back-end
KeyboardManagerState keyboardManagerState;
@@ -63,12 +62,12 @@ private:
public:
// Constructor
PowerKeys()
KeyboardManager()
{
init_map();
// Set the static pointer to the newest object of the class
powerkeys_object_ptr = this;
keyboardmanager_object_ptr = this;
};
// This function is used to add the hardcoded mappings
@@ -113,7 +112,7 @@ public:
// Return the display name of the powertoy, this will be cached by the runner
virtual const wchar_t* get_name() override
{
return MODULE_NAME;
return app_name.c_str();
}
// Return array of the names of all events that this powertoy listens for, with
@@ -133,7 +132,7 @@ public:
// Create a Settings object.
PowerToysSettings::Settings settings(hinstance, get_name());
settings.set_description(MODULE_DESC);
settings.set_description(IDS_SETTINGS_DESCRIPTION);
return settings.serialize_to_buffer(buffer, buffer_size);
}
@@ -218,7 +217,7 @@ public:
{
event.lParam = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
event.wParam = wParam;
if (powerkeys_object_ptr->HandleKeyboardHookEvent(&event) == 1)
if (keyboardmanager_object_ptr->HandleKeyboardHookEvent(&event) == 1)
{
return 1;
}
@@ -312,7 +311,7 @@ public:
intptr_t HandleSingleKeyRemapEvent(LowlevelKeyboardEvent* data) noexcept
{
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
if (!(data->lParam->dwExtraInfo & POWERKEYS_INJECTED_FLAG))
if (!(data->lParam->dwExtraInfo & KEYBOARDMANAGER_INJECTED_FLAG))
{
auto it = keyboardManagerState.singleKeyReMap.find(data->lParam->vkCode);
if (it != keyboardManagerState.singleKeyReMap.end())
@@ -322,14 +321,14 @@ public:
{
return 1;
}
int key_count = 1;
LPINPUT keyEventList = new INPUT[size_t(key_count)]();
memset(keyEventList, 0, sizeof(keyEventList));
keyEventList[0].type = INPUT_KEYBOARD;
keyEventList[0].ki.wVk = it->second;
keyEventList[0].ki.dwFlags = 0;
keyEventList[0].ki.dwExtraInfo = POWERKEYS_SINGLEKEY_FLAG;
keyEventList[0].ki.dwExtraInfo = KEYBOARDMANAGER_SINGLEKEY_FLAG;
if (data->wParam == WM_KEYUP || data->wParam == WM_SYSKEYUP)
{
keyEventList[0].ki.dwFlags = KEYEVENTF_KEYUP;
@@ -348,7 +347,7 @@ public:
intptr_t HandleSingleKeyToggleToModEvent(LowlevelKeyboardEvent* data) noexcept
{
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
if (!(data->lParam->dwExtraInfo & POWERKEYS_INJECTED_FLAG))
if (!(data->lParam->dwExtraInfo & KEYBOARDMANAGER_INJECTED_FLAG))
{
auto it = keyboardManagerState.singleKeyToggleToMod.find(data->lParam->vkCode);
if (it != keyboardManagerState.singleKeyToggleToMod.end())
@@ -371,11 +370,11 @@ public:
keyEventList[0].type = INPUT_KEYBOARD;
keyEventList[0].ki.wVk = (WORD)data->lParam->vkCode;
keyEventList[0].ki.dwFlags = 0;
keyEventList[0].ki.dwExtraInfo = POWERKEYS_SINGLEKEY_FLAG;
keyEventList[0].ki.dwExtraInfo = KEYBOARDMANAGER_SINGLEKEY_FLAG;
keyEventList[1].type = INPUT_KEYBOARD;
keyEventList[1].ki.wVk = (WORD)data->lParam->vkCode;
keyEventList[1].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[1].ki.dwExtraInfo = POWERKEYS_SINGLEKEY_FLAG;
keyEventList[1].ki.dwExtraInfo = KEYBOARDMANAGER_SINGLEKEY_FLAG;
UINT res = SendInput(key_count, keyEventList, sizeof(INPUT));
delete[] keyEventList;
@@ -535,7 +534,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = it.second.first[j];
keyEventList[i].ki.dwFlags = 0;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j++;
@@ -552,7 +551,7 @@ public:
keyEventList[0].type = INPUT_KEYBOARD;
keyEventList[0].ki.wVk = (WORD)DUMMY_KEY;
keyEventList[0].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[0].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[0].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
// Release original shortcut state (release in reverse order of shortcut to be accurate)
long long i = 1;
@@ -565,7 +564,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = (WORD)it.first[j];
keyEventList[i].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j--;
@@ -581,7 +580,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = it.second.first[j];
keyEventList[i].ki.dwFlags = 0;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j++;
@@ -635,7 +634,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = it.second.first[j];
keyEventList[i].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j--;
@@ -651,7 +650,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = (WORD)it.first[j];
keyEventList[i].ki.dwFlags = 0;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j++;
@@ -676,7 +675,7 @@ public:
keyEventList[0].type = INPUT_KEYBOARD;
keyEventList[0].ki.wVk = it.second.first[dest_size - 1];
keyEventList[0].ki.dwFlags = 0;
keyEventList[0].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[0].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
it.second.second = true;
UINT res = SendInput((UINT)key_count, keyEventList, sizeof(INPUT));
@@ -705,7 +704,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = it.second.first[j];
keyEventList[i].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j--;
@@ -729,7 +728,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = it.second.first[j];
keyEventList[i].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j--;
@@ -745,7 +744,7 @@ public:
keyEventList[i].type = INPUT_KEYBOARD;
keyEventList[i].ki.wVk = (WORD)it.first[j];
keyEventList[i].ki.dwFlags = 0;
keyEventList[i].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[i].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
i++;
}
j++;
@@ -755,7 +754,7 @@ public:
keyEventList[key_count - 1].type = INPUT_KEYBOARD;
keyEventList[key_count - 1].ki.wVk = (WORD)DUMMY_KEY;
keyEventList[key_count - 1].ki.dwFlags = KEYEVENTF_KEYUP;
keyEventList[key_count - 1].ki.dwExtraInfo = POWERKEYS_SHORTCUT_FLAG;
keyEventList[key_count - 1].ki.dwExtraInfo = KEYBOARDMANAGER_SHORTCUT_FLAG;
}
it.second.second = false;
@@ -774,7 +773,7 @@ public:
intptr_t HandleOSLevelShortcutRemapEvent(LowlevelKeyboardEvent* data) noexcept
{
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
if (data->lParam->dwExtraInfo != POWERKEYS_SHORTCUT_FLAG)
if (data->lParam->dwExtraInfo != KEYBOARDMANAGER_SHORTCUT_FLAG)
{
return HandleShortcutRemapEvent(data, keyboardManagerState.osLevelShortcutReMap);
}
@@ -832,7 +831,7 @@ public:
intptr_t HandleAppSpecificShortcutRemapEvent(LowlevelKeyboardEvent* data) noexcept
{
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
if (data->lParam->dwExtraInfo != POWERKEYS_SHORTCUT_FLAG)
if (data->lParam->dwExtraInfo != KEYBOARDMANAGER_SHORTCUT_FLAG)
{
std::wstring process_name = GetCurrentApplication(false);
if (process_name.empty())
@@ -851,11 +850,11 @@ public:
}
};
HHOOK PowerKeys::hook_handle = nullptr;
HHOOK PowerKeys::hook_handle_copy = nullptr;
PowerKeys* PowerKeys::powerkeys_object_ptr = nullptr;
HHOOK KeyboardManager::hook_handle = nullptr;
HHOOK KeyboardManager::hook_handle_copy = nullptr;
KeyboardManager* KeyboardManager::keyboardmanager_object_ptr = nullptr;
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new PowerKeys();
return new KeyboardManager();
}