Runner: improve debugging experience with hooks

This commit is contained in:
yuyoyuppe
2020-06-18 14:27:20 +03:00
parent 7ed03c8b90
commit 2effbd0baf
10 changed files with 83 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include <common/settings_objects.h>
#include <common/common.h>
#include <common/debug_control.h>
#include <interface/powertoy_module_interface.h>
#include <interface/lowlevel_keyboard_event_data.h>
#include <interface/win_hook_event_data.h>
@@ -78,11 +79,18 @@ public:
InitializeWinhookEventIds();
Trace::FancyZones::EnableFancyZones(true);
m_app = MakeFancyZones(reinterpret_cast<HINSTANCE>(&__ImageBase), m_settings);
s_llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), NULL);
if (!s_llKeyboardHook)
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
const bool hook_disabled = IsDebuggerPresent();
#else
const bool hook_disabled = false;
#endif
if (!hook_disabled)
{
MessageBoxW(NULL, L"Cannot install keyboard listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
s_llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), NULL);
if (!s_llKeyboardHook)
{
MessageBoxW(NULL, L"Cannot install keyboard listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
}
}
std::array<DWORD, 6> events_to_subscribe = {

View File

@@ -1,5 +1,6 @@
#include "pch.h"
#include "SecondaryMouseButtonsHook.h"
#include <common/debug_control.h>
#pragma region public
@@ -9,11 +10,23 @@ std::function<void()> SecondaryMouseButtonsHook::callback = {};
SecondaryMouseButtonsHook::SecondaryMouseButtonsHook(std::function<void()> extCallback)
{
callback = std::move(extCallback);
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
if (IsDebuggerPresent())
{
return;
}
#endif
hHook = SetWindowsHookEx(WH_MOUSE_LL, SecondaryMouseButtonsProc, GetModuleHandle(NULL), 0);
}
void SecondaryMouseButtonsHook::enable()
{
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
if (IsDebuggerPresent())
{
return;
}
#endif
if (!hHook)
{
hHook = SetWindowsHookEx(WH_MOUSE_LL, SecondaryMouseButtonsProc, GetModuleHandle(NULL), 0);

View File

@@ -1,6 +1,8 @@
#include "pch.h"
#include "ShiftKeyHook.h"
#include <common/debug_control.h>
#pragma region public
HHOOK ShiftKeyHook::hHook = {};
@@ -9,11 +11,23 @@ std::function<void(bool)> ShiftKeyHook::callback = {};
ShiftKeyHook::ShiftKeyHook(std::function<void(bool)> extCallback)
{
callback = std::move(extCallback);
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
if (IsDebuggerPresent())
{
return;
}
#endif
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, ShiftKeyHookProc, GetModuleHandle(NULL), 0);
}
void ShiftKeyHook::enable()
{
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
if (IsDebuggerPresent())
{
return;
}
#endif
if (!hHook)
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, ShiftKeyHookProc, GetModuleHandle(NULL), 0);