-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForm1.cs
213 lines (192 loc) · 7.86 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
namespace simple_mouse_click_tester
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
richTextBox1.MouseWheel += richTextBox1_MouseWheel;
richTextBox1.Text = "Simple mouse click tester that is indended for personal use." +
"\nFeatures:" +
"\n#1. Three modes for testing: Realtime, Highlight and Double Click mode." +
"\n#2. Continuity test: Select RT mode, hold down the desired click and check if the mouse click counter increases." +
"\n#3. Scroll test:Select HL mode, scroll in one direction and check if it highlights the scroll in the other direction." +
"\n#4. Simultaneous click test: Select RT mode, press combinations of clicks (especially LMB+MB3 and MMB+MB4 if your mouse has MB3 and 4) and check if they both highlight at the same time." +
"\n#5. Double click test: Select DC mode and perform single clicks to check if the mouse would perform a faulty doubleclick or check if you can perform double clicks" +
" with that mouse. Works for all buttons and the click counter only records the number of double clicks.\n When you are testing the mouse keep the mouse within this textbox.";
//richTextBox1.DoubleClick += richTextBox1_DoubleClick; //experimental
}
private bool singleClick;
//handle which button needs to be highlighted and what label needs to be updated, for the clicks
public void HandleHighlight(MouseEventArgs a)
{
if (a.Button == MouseButtons.Left)
{
leftMB.BackColor = Color.Blue;
leftLbl.Text = Convert.ToString(Convert.ToInt32(leftLbl.Text) + 1);
}
if (a.Button == MouseButtons.Middle)
{
middleMB.BackColor = Color.Blue;
middleLbl.Text = Convert.ToString(Convert.ToInt32(middleLbl.Text) + 1);
}
if (a.Button == MouseButtons.Right)
{
rightMB.BackColor = Color.Blue;
rightLbl.Text = Convert.ToString(Convert.ToInt32(rightLbl.Text) + 1);
}
if (a.Button == MouseButtons.XButton1)
{
threeMB.BackColor = Color.Blue;
threeLbl.Text = Convert.ToString(Convert.ToInt32(threeLbl.Text) + 1);
}
if (a.Button == MouseButtons.XButton2)
{
fourMB.BackColor = Color.Blue;
fourLbl.Text = Convert.ToString(Convert.ToInt32(fourLbl.Text) + 1);
}
}
//for scrollling
private void richTextBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (timer1.Enabled)
{
timer1.Stop();
}
//int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
if (realtimeRB.Checked || highlightRB.Checked)
{
if ((e.Delta * SystemInformation.MouseWheelScrollLines / 120) > 0)
{
scrollU.BackColor = Color.Blue;
}
if ((e.Delta * SystemInformation.MouseWheelScrollLines / 120) < 0)
{
scrollD.BackColor = Color.Blue;
}
}
if (realtimeRB.Checked)
{
timer1.Start();
}
}
//double click experimental
/*private void richTextBox1_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show("Double click!");
}*/
//when you click
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
if (realtimeRB.Checked||highlightRB.Checked)
{
HandleHighlight(e);
}
if (doubleClickRB.Checked)
{
if (!singleClick)
{
timer2.Start();
singleClick=true;
}
else
{
HandleHighlight(e);
singleClick=false;
}
}
//in case you need to troubleshoot which button was pressed
//richTextBox1.Text+=" "+Convert.ToString(e.Button);
}
//when you release the click
private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
if (realtimeRB.Checked)
{
if (e.Button == MouseButtons.Left)
{
leftMB.BackColor = Control.DefaultBackColor;
}
if (e.Button == MouseButtons.Middle)
{
middleMB.BackColor = Control.DefaultBackColor;
}
if (e.Button == MouseButtons.Right)
{
rightMB.BackColor = Control.DefaultBackColor;
}
if (e.Button == MouseButtons.XButton1)
{
threeMB.BackColor = Control.DefaultBackColor;
}
if (e.Button == MouseButtons.XButton2)
{
fourMB.BackColor = Control.DefaultBackColor;
}
/* switch alternative, deemed flawed
switch (e.Button)
{
case MouseButtons.Left: leftMB.BackColor = Control.DefaultBackColor;
break;
case MouseButtons.Middle: middleMB.BackColor = Control.DefaultBackColor;
break;
case MouseButtons.Right: rightMB.BackColor = Control.DefaultBackColor;
break;
case MouseButtons.XButton1: threeMB.BackColor = Control.DefaultBackColor;
break;
case MouseButtons.XButton2: fourMB.BackColor = Control.DefaultBackColor;
break;
}*/
}
}
//clear fields
private void clearBtn_Click(object sender, EventArgs e)
{
leftMB.BackColor = Control.DefaultBackColor;
middleMB.BackColor = Control.DefaultBackColor;
rightMB.BackColor = Control.DefaultBackColor;
threeMB.BackColor = Control.DefaultBackColor;
fourMB.BackColor = Control.DefaultBackColor;
scrollU.BackColor = Control.DefaultBackColor;
scrollD.BackColor = Control.DefaultBackColor;
leftLbl.Text = "0";
middleLbl.Text = "0";
rightLbl.Text = "0";
threeLbl.Text = "0";
fourLbl.Text = "0";
}
//simple way to clear out the scroll buttons when it stops scrolling
private void timer1_Tick(object sender, EventArgs e)
{
scrollU.BackColor = Control.DefaultBackColor;
scrollD.BackColor = Control.DefaultBackColor;
timer1.Stop();
}
//to accomodate the doubleclick mode
private void doubleClickRB_CheckedChanged(object sender, EventArgs e)
{
if (doubleClickRB.Checked)
{
singleClick = false;
timer2.Interval = SystemInformation.DoubleClickTime;
}
else
{
if(timer2.Enabled)
timer2.Stop();
clearBtn.PerformClick();
}
}
//reset timer if there is no doubleclick
private void timer2_Tick(object sender, EventArgs e)
{
singleClick = false;
timer2.Stop();
}
//reset highlights when out of highlight mode
private void highlightRB_CheckedChanged(object sender, EventArgs e)
{
clearBtn.PerformClick();
}
}
}