Skip to content

Commit

Permalink
clean unused state
Browse files Browse the repository at this point in the history
  • Loading branch information
z committed Dec 21, 2024
1 parent 0aead50 commit 814cf9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
34 changes: 16 additions & 18 deletions Src/MouseHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
,{WM_MOUSEWHEEL, 6}
,{WM_MOUSEHWHEEL, 7}
};
auto it = actionIdx.find(static_cast<UINT>(wParam));
const auto it = actionIdx.find(static_cast<UINT>(wParam));
if (it != actionIdx.end())
{
auto bRet = stateMatrix[static_cast<int>(m_currentState)][it->second](lParam);
const auto bRet = stateMatrix[static_cast<int>(m_currentState)][it->second](lParam);
if (bRet)
return 1;
}
Expand All @@ -80,12 +80,12 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)

bool CMouseHook::MouseWheelAction(LPARAM lParam)
{
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);
const MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
const short zDelta = HIWORD(pMouseStruct->mouseData);

if (GetAsyncKeyState(VK_MENU) & 0x8000)
{
HWND hwndTarget = GetForegroundWindow();
const HWND hwndTarget = GetForegroundWindow();
// When hold Alt key, use nFlags to check MK_CONTROL MK_SHIFT holding got problem, Use GetAsyncKeyState() instead.
const auto bShiftDown = GetAsyncKeyState(VK_SHIFT) & 0x8000;
const auto bControlDown = GetAsyncKeyState(VK_CONTROL) & 0x8000;
Expand Down Expand Up @@ -142,12 +142,12 @@ bool CMouseHook::MouseWheelAction(LPARAM lParam)

bool CMouseHook::MouseHWheelAction(LPARAM lParam)
{
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);
const MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
const short zDelta = HIWORD(pMouseStruct->mouseData);

if (GetAsyncKeyState(VK_MENU) & 0x8000)
{
HWND hwndTarget = GetForegroundWindow();
const HWND hwndTarget = GetForegroundWindow();
const auto bControlDown = GetAsyncKeyState(VK_CONTROL) & 0x8000;
// zDelta > 0 scrool right, < 0 scrool left
if (zDelta > 0)
Expand Down Expand Up @@ -188,33 +188,31 @@ bool CMouseHook::MouseHWheelAction(LPARAM lParam)

bool CMouseHook::RightButtonDown_MouseWheel(LPARAM lParam)
{
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);
HWND hwndTarget = GetForegroundWindow();
const MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
const short zDelta = HIWORD(pMouseStruct->mouseData);
const HWND hwndTarget = GetForegroundWindow();
if (zDelta > 0)
{
// RButton(hold)+ScrollUp as Alt+Up, RButton(hold) MButtonClk WheelScrollUp as Alt+Left
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, (State::HorizontalScrollSimulated == m_currentState) ?
ID_R2L : ID_PREVDIFF, 0);
PostMessage(hwndTarget, WM_COMMAND, ID_PREVDIFF, 0);
return true;
}
else if (zDelta < 0)
{
// RButton(hold)+ScrollDown as Alt+Down, RButton(hold) MButtonClk WheelScrollUp as Alt+Right
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, (State::HorizontalScrollSimulated == m_currentState) ?
ID_L2R : ID_NEXTDIFF, 0);
PostMessage(hwndTarget, WM_COMMAND, ID_NEXTDIFF, 0);
return true;
}
return false;
}

bool CMouseHook::RightButtonDown_MouseHWheel(LPARAM lParam)
{
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);
HWND hwndTarget = GetForegroundWindow();
const MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
const short zDelta = HIWORD(pMouseStruct->mouseData);
const HWND hwndTarget = GetForegroundWindow();
if (zDelta > 0)
{
// RButton+ScrollRight as Alt+Right
Expand Down
3 changes: 1 addition & 2 deletions Src/MouseHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class CMouseHook

enum class State {
Idle,
RightButtonDown,
HorizontalScrollSimulated
RightButtonDown
};
inline static State m_currentState = State::Idle;
inline static void Transition(State nextState) { m_currentState = nextState; };
Expand Down

0 comments on commit 814cf9e

Please sign in to comment.