-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
272 lines (251 loc) · 10.1 KB
/
Form1.cs
File metadata and controls
272 lines (251 loc) · 10.1 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Colore = Corale.Colore.Core.Color;
using Color = System.Drawing.Color;
using static RazerKeyboardRecoloring.Extentions;
using System.Data.Common;
using System.Text.RegularExpressions;
using Corale.Colore.Core;
using Corale.Colore.Razer.Keyboard;
namespace RazerKeyboardRecoloring
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Start();
}
public static DateTime startTime;
public static Button[,] keyboardButtons;
public static Colore[][] keyboardColores = new Colore[6][];
private static bool buttonsInitiated;
private static bool running;
private static bool toggleRainbowHue;
public void Start()
{
InitControl();
startTime = DateTime.Now;
Console.WriteLine("Razer keyboard recoloring started");
Corale.Colore.Core.Chroma._instance = new Corale.Colore.Core.Chroma();
running = true;
Thread.Sleep(1000);
Thread colorsUpdate = new Thread(() =>
{
while (!buttonsInitiated)
Thread.Sleep(100);
while (running)
{
Thread.Sleep(50);
try
{
if (toggleRainbowHue)
{
List<Colore> coloresList = new List<Colore>();
Colore[] columns;
coloresList.Clear();
columns = Extentions.GetAnimatedGradient(22, rainbowHUE, false, 2, 0.5f).ToColore().Reverse().ToArray();
//columns = new Colore[6] { Colore.White, Colore.White, Colore.White, Colore.White, Colore.White, Colore.White };
var hueColors = new Colore[][] { columns, columns, columns, columns, columns, columns };
for (int row = 0; row < 6; row++)
{
var tempColores = new Colore[22];
for (int column = 0; column < 22; column++)
{
keyboardButtons[row, column].BackColor = hueColors[row][column].ToColor();
}
}
Keyboard.Instance.Set(hueColors);
Mouse.Instance.Set(columns[12]); //6 element from 6 [5] and 12 [11] el from 22 where 11 for each part of keyboard
}
else
{
Keyboard.Instance.Set(keyboardColores);
Mouse.Instance.Set(keyboardColores[0][21]);
}
}
catch (Exception exc)
{
MessageBox.Show($"Exception: {exc.Message}");
}
}
});
colorsUpdate.IsBackground = true;
colorsUpdate.Start();
}
public void InitControl()
{
keyboardButtons = new Button[6, 22];
int rows = 6;
int columns = 22;
this.SuspendLayout();
for (int row = 0; row < rows; row++)
{
var tempColores = new Colore[22];
for (int column = 0; column < columns; column++)
{
var button = new Button();
button.Location = new System.Drawing.Point(50 * column, 100 + (50 * row));
button.Name = $"button_row{row}_column{column}";
button.Size = new System.Drawing.Size(50, 50);
button.TabIndex = 0;
button.UseVisualStyleBackColor = true;
button.BackColor = Color.White;
button.MouseDown += Button_MouseClick;
this.Controls.Add(button);
keyboardButtons[row,column] = button;
tempColores[column] = Colore.White;
}
keyboardColores[row] = tempColores;
}
this.ResumeLayout(false);
buttonsInitiated = true;
}
private void lmbColorBtn_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
var button = ((Button)sender);
var name = button.Name;
var mouseButton = e.Button;
if (mouseButton == MouseButtons.Left)
{
ColorDialog col = new ColorDialog();
if (col.ShowDialog() == DialogResult.OK)
{
button.BackColor = col.Color;
}
}
else
button.BackColor = name.StartsWith("lmb") ? Color.Red :
name.StartsWith("rmb") ? Color.Yellow :
name.StartsWith("mmb") ? Color.Green :
name.StartsWith("mb4") ? Color.Cyan :
name.StartsWith("mb5") ? Color.Purple : Color.White;
}
private void Button_MouseClick(object sender, MouseEventArgs e)
{
var mouseButton = e.Button;
Color finalColor = Color.White;
switch (mouseButton)
{
case MouseButtons.Left:
finalColor = lmbColorBtn.BackColor;
break;
case MouseButtons.Right:
finalColor = rmbColorBtn.BackColor;
break;
case MouseButtons.Middle:
finalColor = mmbColorBtn.BackColor;
break;
case MouseButtons.XButton1:
finalColor = mb5ColorBtn.BackColor;
break;
case MouseButtons.XButton2:
finalColor = mb4ColorBtn.BackColor;
break;
default:
break;
}
var name = ((Button)sender).Name;
var row = int.Parse(Regex.Split(Regex.Split(name, "row")[1], "_")[0]);
var column = int.Parse(Regex.Split(name, "column")[1]);
keyboardColores[row][column] = finalColor.ToColore();
keyboardButtons[row, column].BackColor = finalColor;
/*MessageBox.Show($"{mouseButton} ({(int)mouseButton}");
var currentColor = Color.White;
switch (currentKey)
{
case 0:
currentColor = Color.White;
break;
case 1:
currentColor = Color.Red;
break;
case 2:
currentColor = Color.Green;
break;
case 3:
currentColor = Color.Blue;
break;
case 4:
currentColor = Color.Magenta;
break;
case 5:
currentColor = Color.Yellow;
break;
case 6:
currentColor = Color.Cyan;
break;
default:
currentColor = Color.White;
break;
}
keyboardColores[row][column] = currentColor.ToColore();
keyboardButtons[row, column].BackColor = currentColor;
return;
//MessageBox.Show($"name: {name} row: {row} column: {column}");
ColorDialog col = new ColorDialog();
//var oldColore = keyboardColores[row][column];
//coloreSelecting = true;
if (col.ShowDialog() == DialogResult.OK)
{
var color = col.Color;
//MessageBox.Show($"{color.R}, {color.G}, {color.B}");
keyboardColores[row][column] = color.ToColore();
keyboardButtons[row, column].BackColor = color;
}
//var newColore = keyboardColores[row][column];
//MessageBox.Show($"old colore: {oldColore.R}, {oldColore.G}, {oldColore.B}\nnew colore: {newColore.R}, {newColore.G}, {newColore.B}");
//coloreSelecting = false;*/
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
running = false;
}
private void RecolorKeyboard_Click(object sender, MouseEventArgs e)
{
var button = e.Button;
if (button == MouseButtons.Left)
{
ColorDialog col = new ColorDialog();
if (col.ShowDialog() == DialogResult.OK)
{
var color = col.Color;
for (int row = 0; row < 6; row++)
{
var tempColores = new Colore[22];
for (int column = 0; column < 22; column++)
{
tempColores[column] = color.ToColore();
keyboardButtons[row, column].BackColor = color;
}
keyboardColores[row] = tempColores;
}
}
}
else
{
toggleRainbowHue = !toggleRainbowHue;
if (!toggleRainbowHue)
{
for (int row = 0; row < 6; row++)
{
var tempColores = new Colore[22];
for (int column = 0; column < 22; column++)
{
keyboardButtons[row, column].BackColor = keyboardColores[row][column].ToColor();
}
}
}
}
}
private void recolorKeyboard_MouseDown(object sender, MouseEventArgs e) => RecolorKeyboard_Click(sender, e);
}
}