Skip to content

Commit 507d0e0

Browse files
committed
Optimize mouse hook function
1 parent e7ca2f6 commit 507d0e0

File tree

4 files changed

+57
-52
lines changed

4 files changed

+57
-52
lines changed

DoubleClickFix.pro.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 3.6.1, 2016-06-30T14:46:45. -->
3+
<!-- Written by QtCreator 3.6.1, 2016-07-03T11:11:18. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -61,7 +61,7 @@
6161
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.6.0 MSVC2013 32bit</value>
6262
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.6.0 MSVC2013 32bit</value>
6363
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.56.win32_msvc2013_kit</value>
64-
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
64+
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
6565
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
6666
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
6767
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">

mainwindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<enum>Qt::NoFocus</enum>
2424
</property>
2525
<property name="windowTitle">
26-
<string>QDoubleClickFix Beta 0.7.1</string>
26+
<string>QDoubleClickFix Beta 0.7.2</string>
2727
</property>
2828
<property name="windowIcon">
2929
<iconset resource="basic_resources.qrc">

meta_data.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ IDI_ICON1 ICON "icon.ico"
2020

2121
#include <windows.h>
2222

23-
#define VER_FILEVERSION 0,7,1
24-
#define VER_FILEVERSION_STR "0.7.1.0\0"
25-
#define VER_PRODUCTVERSION 0,7,1
26-
#define VER_PRODUCTVERSION_STR "0.7.1\0"
23+
#define VER_FILEVERSION 0,7,2
24+
#define VER_FILEVERSION_STR "0.7.2.0\0"
25+
#define VER_PRODUCTVERSION 0,7,2
26+
#define VER_PRODUCTVERSION_STR "0.7.2\0"
2727
#define VER_FILEDESCRIPTION_STR "Double Click Problem Fixer Tool"
2828
#define VER_INTERNALNAME_STR "DoubleClickFix"
2929
#define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2016 Alik Aslanyan"

mousecatcherthread.cpp

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,6 @@ LRESULT inline MouseCatcherThread::MouseCallBackProc(int nCode, WPARAM wParam, L
6969
bool isRight = wParam==WM_RBUTTONDOWN;
7070
int iMSecs = m_ClickTimer.elapsed();
7171
m_ClickTimer.restart();
72-
73-
74-
if(isMouseHoldAutoSelectionMode())
75-
{
76-
QTimer *t = new QTimer();
77-
t->setSingleShot(true);
78-
t->setInterval(getMouseHoldingDelay());
79-
t->moveToThread(this);
80-
connect(this, SIGNAL(mouse_up()), t, SLOT(stop()));
81-
connect(this, SIGNAL(mouse_up()), t, SLOT(deleteLater()));
82-
83-
connect(this, SIGNAL(finished()), t, SLOT(stop()));
84-
connect(this, SIGNAL(finished()), t, SLOT(deleteLater()));
85-
86-
87-
connect(t, &QTimer::timeout, [this](){
88-
89-
setSelectionMode(true);
90-
m_iToggled=true;
91-
});
92-
93-
94-
t->start();
95-
}
9672
bool needLog = isLoggingStarted();
9773

9874
if(getDelay()>=iMSecs)
@@ -106,25 +82,50 @@ LRESULT inline MouseCatcherThread::MouseCallBackProc(int nCode, WPARAM wParam, L
10682
emit delay(iMSecs, false, isRight);
10783
}
10884

109-
if(m_iToggled && wParam==WM_LBUTTONDOWN)
110-
{
111-
m_iToggled=!m_iToggled;
112-
113-
POINT p;
114-
GetCursorPos(&p);
115-
INPUT ip;
116-
memset(&ip, 0, sizeof(INPUT));
117-
ip.type = INPUT_MOUSE;
118-
ip.mi.dx = p.x;
119-
ip.mi.dy = p.y;
120-
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
121-
SendInput(1, &ip, sizeof(INPUT));
122-
setSelectionMode(false);
123-
return BLOCK_CALL;
124-
}
125-
else if(isSelectionMode())
85+
if(!isRight)
12686
{
127-
m_iToggled=!m_iToggled;
87+
if(m_iToggled)
88+
{
89+
m_iToggled=false;
90+
91+
POINT p;
92+
GetCursorPos(&p);
93+
INPUT ip;
94+
memset(&ip, 0, sizeof(INPUT));
95+
ip.type = INPUT_MOUSE;
96+
ip.mi.dx = p.x;
97+
ip.mi.dy = p.y;
98+
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
99+
SendInput(1, &ip, sizeof(INPUT));
100+
setSelectionMode(false);
101+
return BLOCK_CALL;
102+
}
103+
else if(isSelectionMode())
104+
{
105+
m_iToggled=true;
106+
}
107+
else if(isMouseHoldAutoSelectionMode())
108+
{
109+
110+
QTimer *t = new QTimer();
111+
t->setSingleShot(true);
112+
t->setInterval(getMouseHoldingDelay());
113+
t->moveToThread(this);
114+
connect(this, SIGNAL(mouse_up()), t, SLOT(stop()));
115+
connect(this, SIGNAL(mouse_up()), t, SLOT(deleteLater()));
116+
117+
connect(this, SIGNAL(finished()), t, SLOT(stop()));
118+
connect(this, SIGNAL(finished()), t, SLOT(deleteLater()));
119+
120+
121+
connect(t, &QTimer::timeout, [this](){
122+
setSelectionMode(true);
123+
m_iToggled=true;
124+
});
125+
126+
127+
t->start();
128+
}
128129
}
129130
}
130131
break;
@@ -133,16 +134,20 @@ LRESULT inline MouseCatcherThread::MouseCallBackProc(int nCode, WPARAM wParam, L
133134
{
134135
if(isStarted())
135136
{
136-
if(m_iToggled && wParam==WM_LBUTTONUP)
137+
short index = short(wParam==WM_RBUTTONUP);
138+
if((m_iToggled || isSelectionMode()) && index==0)
137139
{
140+
if(iBlockMouseButtonUps[index]>0)
141+
{
142+
--iBlockMouseButtonUps[index];
143+
}
138144
return BLOCK_CALL;
139145
}
140146
else
141147
{
142-
int index = (int)wParam==WM_RBUTTONUP;
143148
if(iBlockMouseButtonUps[index]>0)
144149
{
145-
iBlockMouseButtonUps[index]--;
150+
--iBlockMouseButtonUps[index];
146151
return BLOCK_CALL;
147152
}
148153
else if(isMouseHoldAutoSelectionMode())

0 commit comments

Comments
 (0)