2020-06-05 22:53:08 +08:00
|
|
|
#include "pch.h"
|
|
|
|
#include "SecondaryMouseButtonsHook.h"
|
2020-06-18 19:27:20 +08:00
|
|
|
#include <common/debug_control.h>
|
2020-06-05 22:53:08 +08:00
|
|
|
|
|
|
|
#pragma region public
|
|
|
|
|
|
|
|
HHOOK SecondaryMouseButtonsHook::hHook = {};
|
|
|
|
std::function<void()> SecondaryMouseButtonsHook::callback = {};
|
|
|
|
|
|
|
|
SecondaryMouseButtonsHook::SecondaryMouseButtonsHook(std::function<void()> extCallback)
|
|
|
|
{
|
|
|
|
callback = std::move(extCallback);
|
2020-06-18 19:27:20 +08:00
|
|
|
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-05 22:53:08 +08:00
|
|
|
hHook = SetWindowsHookEx(WH_MOUSE_LL, SecondaryMouseButtonsProc, GetModuleHandle(NULL), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SecondaryMouseButtonsHook::enable()
|
|
|
|
{
|
2020-06-18 19:27:20 +08:00
|
|
|
#if defined(DISABLE_LOWLEVEL_KBHOOK_WHEN_DEBUGGED)
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-05 22:53:08 +08:00
|
|
|
if (!hHook)
|
|
|
|
{
|
|
|
|
hHook = SetWindowsHookEx(WH_MOUSE_LL, SecondaryMouseButtonsProc, GetModuleHandle(NULL), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SecondaryMouseButtonsHook::disable()
|
|
|
|
{
|
|
|
|
if (hHook)
|
|
|
|
{
|
|
|
|
UnhookWindowsHookEx(hHook);
|
|
|
|
hHook = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region private
|
|
|
|
|
|
|
|
LRESULT CALLBACK SecondaryMouseButtonsHook::SecondaryMouseButtonsProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (nCode == HC_ACTION)
|
|
|
|
{
|
|
|
|
if (wParam == (GetSystemMetrics(SM_SWAPBUTTON) ? WM_LBUTTONDOWN : WM_RBUTTONDOWN) || wParam == WM_MBUTTONDOWN || wParam == WM_XBUTTONDOWN)
|
|
|
|
{
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CallNextHookEx(hHook, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|