-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainForm.cs
142 lines (130 loc) · 4.38 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KeyRateGUI
{
public partial class MainForm : Form
{
public MainForm()
{
ConfigController.LoadConfig();
InitializeComponent();
InitializeComponentFunctions();
}
private void InitializeComponentFunctions()
{
textBoxDelay.KeyPress += textBoxDelay_KeyPress;
textBoxRepeat.KeyPress += textBoxRepeat_KeyPress;
buttonSet.Click += buttonSet_Click;
buttonReset.Click += buttonReset_Click;
buttonClear.Click += buttonClear_Click;
linkLabelSource.LinkClicked += linkLabelSource_LinkClicked;
// set repeat, delay and autosave
textBoxDelay.Text = ConfigController.DelayMSec.ToString();
textBoxRepeat.Text = ConfigController.RepeatMSec.ToString();
checkBoxSaveSettings.Checked = ConfigController.AutoSave;
}
private void textBoxDelay_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 8)
{
return;
}
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
else if (textBoxDelay.Text.Length > 3 && textBoxDelay.SelectedText.Length == 0)
{
e.Handled = true;
}
}
private void textBoxRepeat_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 8)
{
return;
}
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
else if (textBoxRepeat.Text.Length > 3 && textBoxDelay.SelectedText.Length == 0)
{
e.Handled = true;
}
}
private void buttonSet_Click(object sender, EventArgs e)
{
if (textBoxDelay.Text == string.Empty)
{
textBoxDelay.Text = "0";
}
if (textBoxRepeat.Text == string.Empty)
{
textBoxRepeat.Text = "0";
}
uint delay = Convert.ToUInt32(textBoxDelay.Text);
uint repeat = Convert.ToUInt32(textBoxRepeat.Text);
bool success = KeyRateController.SetFilterKeys(delay, repeat);
if (success)
{
textBoxTest.Text = string.Empty;
labelResult.ForeColor = Color.Green;
labelResult.Text = "Keyrate set successfully!";
if (ConfigController.AutoSave)
{
ConfigController.DelayMSec = delay;
ConfigController.RepeatMSec = repeat;
ConfigController.SaveConfig();
}
}
else
{
labelResult.ForeColor = Color.Red;
labelResult.Text = "Syscall failed!";
}
}
private void buttonReset_Click(object sender, EventArgs e)
{
bool success = KeyRateController.ResetFilterKeys();
if (success)
{
textBoxTest.Text = string.Empty;
labelResult.ForeColor = Color.Orange;
labelResult.Text = "Keyrate reset!";
}
else
{
labelResult.ForeColor = Color.Red;
labelResult.Text = "Syscall failed!";
}
}
private void buttonClear_Click(object sender, EventArgs e)
{
textBoxTest.Text = string.Empty;
}
private void linkLabelSource_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabelSource.LinkVisited = true;
var uri = "https://github.com/NumberPigeon/keyrateGUI";
var psi = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = true,
FileName = uri
};
System.Diagnostics.Process.Start(psi);
}
private void checkBoxSaveSettings_CheckedChanged(object sender, EventArgs e)
{
ConfigController.AutoSave = checkBoxSaveSettings.Checked;
ConfigController.SaveConfig();
}
}
}