Fixed KBM interaction with Shortcut Guide (#2220)

This commit is contained in:
Arjun Balgovind 2020-04-21 10:25:14 -07:00 committed by GitHub
parent 93752fb6cb
commit b715a008c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 3 deletions

View File

@ -124,6 +124,7 @@
<ClInclude Include="keyboard_layout.h" />
<ClInclude Include="keyboard_layout_impl.h" />
<ClInclude Include="notifications.h" />
<ClInclude Include="shared_constants.h" />
<ClInclude Include="timeutil.h" />
<ClInclude Include="VersionHelper.h" />
<ClInclude Include="window_helpers.h" />

View File

@ -99,6 +99,9 @@
<ClInclude Include="com_object_factory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="shared_constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="keyboard_layout_impl.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -0,0 +1,8 @@
#pragma once
#include "common.h"
namespace CommonSharedConstants
{
// Flag that can be set on an input event so that it is ignored by Keyboard Manager
const ULONG_PTR KEYBOARDMANAGER_INJECTED_FLAG = 0x1;
}

View File

@ -3,6 +3,7 @@
#include <interface/lowlevel_keyboard_event_data.h>
#include <interface/win_hook_event_data.h>
#include <common/settings_objects.h>
#include <common/shared_constants.h>
#include "trace.h"
#include "resource.h"
#include <keyboardmanager/ui/EditKeyboardWindow.h>
@ -43,7 +44,6 @@ private:
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;
@ -407,7 +407,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 & KEYBOARDMANAGER_INJECTED_FLAG))
if (!(data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG))
{
// The mutex should be unlocked before SendInput is called to avoid re-entry into the same mutex. More details can be found at https://github.com/microsoft/PowerToys/pull/1789#issuecomment-607555837
std::unique_lock<std::mutex> lock(keyboardManagerState.singleKeyReMap_mutex);
@ -446,7 +446,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 & KEYBOARDMANAGER_INJECTED_FLAG))
if (!(data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG))
{
// The mutex should be unlocked before SendInput is called to avoid re-entry into the same mutex. More details can be found at https://github.com/microsoft/PowerToys/pull/1789#issuecomment-607555837
std::unique_lock<std::mutex> lock(keyboardManagerState.singleKeyToggleToMod_mutex);

View File

@ -2,6 +2,7 @@
#include "target_state.h"
#include "common/start_visible.h"
#include "keyboard_state.h"
#include "common/shared_constants.h"
TargetState::TargetState(int ms_delay) :
delay(std::chrono::milliseconds(ms_delay)), thread(&TargetState::thread_proc, this)
@ -42,12 +43,15 @@ bool TargetState::signal_event(unsigned vk_code, bool key_down)
INPUT input[3] = { {}, {}, {} };
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0xCF;
input[0].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0xCF;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
input[1].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG;
input[2].type = INPUT_KEYBOARD;
input[2].ki.wVk = VK_LWIN;
input[2].ki.dwFlags = KEYEVENTF_KEYUP;
input[2].ki.dwExtraInfo = CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG;
SendInput(3, input, sizeof(INPUT));
}
return supress;