Skip to content

Commit

Permalink
[FindMyMouse]Minimum delay and left ctrl exit (#14045)
Browse files Browse the repository at this point in the history
* [FindMyMouse]Minimum delay and left ctrl exit

* Update mouse snooping as well.
  • Loading branch information
jaimecbernardo committed Oct 29, 2021
1 parent 6dd74f5 commit 25a83c0
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct SuperSonar
HWND m_hwnd;
POINT m_sonarPos = ptNowhere;

// Only consider double left control click if at least 100ms passed between the clicks, to avoid keyboards that might be sending rapid clicks.
static const int MIN_DOUBLE_CLICK_TIME = 100;

static constexpr int SonarRadius = 100;
static constexpr int SonarZoomFactor = 9;
static constexpr DWORD FadeDuration = 500;
Expand Down Expand Up @@ -304,23 +307,39 @@ void SuperSonar<D>::OnSonarKeyboardInput(RAWINPUT const& input)
break;

case SonarState::ControlUp1:
case SonarState::ControlUp2:
if (pressed)
{
m_sonarState = SonarState::ControlDown2;
auto now = GetTickCount();
auto doubleClickInterval = now - m_lastKeyTime;
POINT ptCursor{};
if (GetCursorPos(&ptCursor) &&
now - m_lastKeyTime <= GetDoubleClickTime() &&
doubleClickInterval >= MIN_DOUBLE_CLICK_TIME &&
doubleClickInterval <= GetDoubleClickTime() &&
IsEqual(m_lastKeyPos, ptCursor))
{
m_sonarState = SonarState::ControlDown2;
StartSonar();
}
else
{
m_sonarState = SonarState::ControlDown1;
m_lastKeyTime = GetTickCount();
m_lastKeyPos = {};
GetCursorPos(&m_lastKeyPos);
UpdateMouseSnooping();
}
Logger::info("Detecting double left control click with {} ms interval.", doubleClickInterval);
m_lastKeyTime = now;
m_lastKeyPos = ptCursor;
}
break;

case SonarState::ControlUp2:
// Also deactivate sonar with left control.
if (pressed)
{
StopSonar();
}
break;
case SonarState::ControlDown2:
if (!pressed)
{
Expand Down

0 comments on commit 25a83c0

Please sign in to comment.