-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
780 lines (721 loc) · 27.1 KB
/
mainwindow.cpp
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
#include "mainwindow.h"
#include "include/CUESDK.h"
#include <QCoreApplication>
#include <QtGui>
#include <QtWidgets>
#include <QtCore>
#include <Windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdexcept>
#include <algorithm>
#include <thread>
MainWindow * mwReference;
const std::vector<CorsairLedId> AREA_ONE {
CLK_Z, CLK_X, CLK_C, CLK_V, CLK_A, CLK_S, CLK_D,
CLK_F, CLK_R, CLK_E, CLK_W, CLK_Q, CLK_1, CLK_2, CLK_3, CLK_4, CLK_T, CLK_G, CLK_B, CLK_5};
const std::vector<CorsairLedId> AREA_TWO {
CLK_B, CLK_N, CLK_M, CLK_CommaAndLessThan, CLK_PeriodAndBiggerThan,
CLK_SlashAndQuestionMark, CLK_H, CLK_J, CLK_K, CLK_L, CLK_SemicolonAndColon,
CLK_Y, CLK_U, CLK_I, CLK_O, CLK_P, CLK_6, CLK_7, CLK_8, CLK_9, CLK_0 };
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
//Key hook callback function
if (nCode == HC_ACTION)
{
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
PKBDLLHOOKSTRUCT hookData = (PKBDLLHOOKSTRUCT)lParam;
if ((wParam == WM_KEYUP) || (wParam == WM_SYSKEYUP)) { //Only on key up
//mwReference->lightKeys((char)hookData->vkCode);
char keyChar = (char)hookData->vkCode;
std::thread lightingThread([&keyChar] {
mwReference->lightKeys(keyChar);
});
lightingThread.join();
}
else {
break;
}
break;
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
void setSize(int x, int y, QWidget* Window)
{
//Function forces window size not allowing rescale
Window->resize(x,y);
Window->setMinimumSize(x,y);
Window->setMaximumSize(x,y);
}
const char* toString(CorsairError error) //Corsair generic error conversion
{
switch (error) {
case CE_Success :
return "CE_Success";
case CE_ServerNotFound:
return "CE_ServerNotFound";
case CE_NoControl:
return "CE_NoControl";
case CE_ProtocolHandshakeMissing:
return "CE_ProtocolHandshakeMissing";
case CE_IncompatibleProtocol:
return "CE_IncompatibleProtocol";
case CE_InvalidArguments:
return "CE_InvalidArguments";
default:
return "unknown error";
}
}
std::vector<CorsairLedColor> getCharLights(char key, CorsairLedColor charColor) {
std::vector<CorsairLedColor> litKeys;
switch (key) {
//Definitions for characters
case 'A':
litKeys.assign(8, charColor);
litKeys[0].ledId = CLK_Z;
litKeys[1].ledId = CLK_S;
litKeys[2].ledId = CLK_E;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_R;
litKeys[5].ledId = CLK_F;
litKeys[6].ledId = CLK_V;
litKeys[7].ledId = CLK_D;
break;
case 'Z':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_Z;
litKeys[1].ledId = CLK_X;
litKeys[2].ledId = CLK_C;
litKeys[3].ledId = CLK_V;
litKeys[4].ledId = CLK_S;
litKeys[5].ledId = CLK_E;
litKeys[6].ledId = CLK_1;
litKeys[7].ledId = CLK_2;
litKeys[8].ledId = CLK_3;
litKeys[9].ledId = CLK_4;
break;
case 'Q':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_E;
litKeys[4].ledId = CLK_D;
litKeys[5].ledId = CLK_S;
litKeys[6].ledId = CLK_A;
litKeys[7].ledId = CLK_Q;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_V;
break;
case 'W':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_S;
litKeys[5].ledId = CLK_C;
litKeys[6].ledId = CLK_F;
litKeys[7].ledId = CLK_R;
litKeys[8].ledId = CLK_5;
litKeys[9].ledId = CLK_D;
break;
case 'S':
litKeys.assign(6, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_W;
litKeys[3].ledId = CLK_D;
litKeys[4].ledId = CLK_X;
litKeys[5].ledId = CLK_Z;
break;
case 'X':
litKeys.assign(8, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_W;
litKeys[2].ledId = CLK_D;
litKeys[3].ledId = CLK_V;
litKeys[4].ledId = CLK_Z;
litKeys[5].ledId = CLK_S;
litKeys[6].ledId = CLK_E;
litKeys[7].ledId = CLK_4;
break;
case 'E':
litKeys.assign(12, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_W;
litKeys[6].ledId = CLK_E;
litKeys[7].ledId = CLK_A;
litKeys[8].ledId = CLK_Z;
litKeys[9].ledId = CLK_X;
litKeys[10].ledId = CLK_C;
litKeys[11].ledId = CLK_V;
break;
case 'D':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_R;
litKeys[3].ledId = CLK_F;
litKeys[4].ledId = CLK_X;
litKeys[5].ledId = CLK_Z;
litKeys[6].ledId = CLK_A;
litKeys[7].ledId = CLK_Q;
litKeys[8].ledId = CLK_3;
litKeys[9].ledId = CLK_C;
break;
case 'C':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_2;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_Z;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_V;
break;
case 'R':
litKeys.assign(6, charColor);
litKeys[0].ledId = CLK_2;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_4;
litKeys[3].ledId = CLK_Q;
litKeys[4].ledId = CLK_A;
litKeys[5].ledId = CLK_Z;
break;
case 'F':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_S;
litKeys[7].ledId = CLK_D;
litKeys[8].ledId = CLK_F;
litKeys[9].ledId = CLK_Z;
break;
case 'V':
litKeys.assign(7, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_S;
litKeys[3].ledId = CLK_X;
litKeys[4].ledId = CLK_D;
litKeys[5].ledId = CLK_R;
litKeys[6].ledId = CLK_5;
break;
case 'T':
litKeys.assign(7, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_W;
litKeys[5].ledId = CLK_S;
litKeys[6].ledId = CLK_X;
break;
case 'G':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_2;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_Z;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_D;
break;
case 'B':
litKeys.assign(8, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_S;
litKeys[4].ledId = CLK_D;
litKeys[5].ledId = CLK_C;
litKeys[6].ledId = CLK_X;
litKeys[7].ledId = CLK_Z;
break;
case 'Y':
litKeys.assign(6, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_S;
litKeys[3].ledId = CLK_X;
litKeys[4].ledId = CLK_E;
litKeys[5].ledId = CLK_4;
break;
case 'H':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_S;
litKeys[5].ledId = CLK_D;
litKeys[6].ledId = CLK_F;
litKeys[7].ledId = CLK_V;
litKeys[8].ledId = CLK_R;
litKeys[9].ledId = CLK_4;
break;
case 'N':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_W;
litKeys[5].ledId = CLK_D;
litKeys[6].ledId = CLK_V;
litKeys[7].ledId = CLK_F;
litKeys[8].ledId = CLK_R;
litKeys[9].ledId = CLK_4;
break;
case 'U':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_X;
litKeys[5].ledId = CLK_C;
litKeys[6].ledId = CLK_V;
litKeys[7].ledId = CLK_F;
litKeys[8].ledId = CLK_R;
litKeys[9].ledId = CLK_4;
break;
case 'J':
litKeys.assign(8, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_E;
litKeys[5].ledId = CLK_D;
litKeys[6].ledId = CLK_C;
litKeys[7].ledId = CLK_X;
break;
case 'M':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_Z;
litKeys[1].ledId = CLK_A;
litKeys[2].ledId = CLK_Q;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_W;
litKeys[5].ledId = CLK_E;
litKeys[6].ledId = CLK_4;
litKeys[7].ledId = CLK_R;
litKeys[8].ledId = CLK_F;
litKeys[9].ledId = CLK_V;
break;
case 'I':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_W;
litKeys[5].ledId = CLK_S;
litKeys[6].ledId = CLK_Z;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_V;
break;
case 'O':
litKeys.assign(12, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_2;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_Z;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_V;
litKeys[10].ledId = CLK_F;
litKeys[11].ledId = CLK_R;
break;
case 'L':
litKeys.assign(7, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_X;
litKeys[5].ledId = CLK_C;
litKeys[6].ledId = CLK_V;
break;
case 'P':
litKeys.assign(9, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_Z;
litKeys[4].ledId = CLK_2;
litKeys[5].ledId = CLK_S;
litKeys[6].ledId = CLK_3;
litKeys[7].ledId = CLK_E;
litKeys[8].ledId = CLK_D;
break;
case '1':
litKeys.assign(8, charColor);
litKeys[0].ledId = CLK_Q;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_W;
litKeys[3].ledId = CLK_S;
litKeys[4].ledId = CLK_Z;
litKeys[5].ledId = CLK_X;
litKeys[6].ledId = CLK_C;
litKeys[7].ledId = CLK_V;
break;
case '2':
litKeys.assign(9, charColor);
litKeys[0].ledId = CLK_Q;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_E;
litKeys[4].ledId = CLK_D;
litKeys[5].ledId = CLK_X;
litKeys[6].ledId = CLK_C;
litKeys[7].ledId = CLK_Z;
litKeys[8].ledId = CLK_V;
break;
case '3':
litKeys.assign(11, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_2;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_4;
litKeys[4].ledId = CLK_R;
litKeys[5].ledId = CLK_E;
litKeys[6].ledId = CLK_F;
litKeys[7].ledId = CLK_V;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_X;
litKeys[10].ledId = CLK_Z;
break;
case '4':
litKeys.assign(9, charColor);
litKeys[0].ledId = CLK_1;
litKeys[1].ledId = CLK_Q;
litKeys[2].ledId = CLK_A;
litKeys[3].ledId = CLK_S;
litKeys[4].ledId = CLK_D;
litKeys[5].ledId = CLK_F;
litKeys[6].ledId = CLK_C;
litKeys[7].ledId = CLK_E;
litKeys[8].ledId = CLK_3;
break;
case '5':
litKeys.assign(9, charColor);
litKeys[0].ledId = CLK_2;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_4;
litKeys[3].ledId = CLK_Q;
litKeys[4].ledId = CLK_S;
litKeys[5].ledId = CLK_D;
litKeys[6].ledId = CLK_C;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_Z;
break;
case '6':
litKeys.assign(11, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_2;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_S;
litKeys[7].ledId = CLK_D;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_X;
litKeys[10].ledId = CLK_Z;
break;
case '7':
litKeys.assign(6, charColor);
litKeys[0].ledId = CLK_X;
litKeys[1].ledId = CLK_S;
litKeys[2].ledId = CLK_W;
litKeys[3].ledId = CLK_2;
litKeys[4].ledId = CLK_3;
litKeys[5].ledId = CLK_4;
break;
case '8':
litKeys.assign(9, charColor);
litKeys[0].ledId = CLK_2;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_W;
litKeys[3].ledId = CLK_E;
litKeys[4].ledId = CLK_A;
litKeys[5].ledId = CLK_D;
litKeys[6].ledId = CLK_Q;
litKeys[7].ledId = CLK_Z;
litKeys[8].ledId = CLK_X;
break;
case '9':
litKeys.assign(10, charColor);
litKeys[0].ledId = CLK_2;
litKeys[1].ledId = CLK_W;
litKeys[2].ledId = CLK_3;
litKeys[3].ledId = CLK_E;
litKeys[4].ledId = CLK_4;
litKeys[5].ledId = CLK_R;
litKeys[6].ledId = CLK_F;
litKeys[7].ledId = CLK_V;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_X;
break;
case '0':
litKeys.assign(12, charColor);
litKeys[0].ledId = CLK_4;
litKeys[1].ledId = CLK_3;
litKeys[2].ledId = CLK_2;
litKeys[3].ledId = CLK_1;
litKeys[4].ledId = CLK_Q;
litKeys[5].ledId = CLK_A;
litKeys[6].ledId = CLK_Z;
litKeys[7].ledId = CLK_X;
litKeys[8].ledId = CLK_C;
litKeys[9].ledId = CLK_V;
litKeys[10].ledId = CLK_F;
litKeys[11].ledId = CLK_R;
break;
}
return litKeys;
}
std::vector<CorsairLedColor> getAvailableKeys(bool checkColor, int r, int g, int b)
{
//get all keys on board
//if checkColor is true will return only keys with matching colors to input
auto colorsVector = std::vector<CorsairLedColor>();
auto colors = mwReference->currentbgColors();
auto ledPositions = CorsairGetLedPositions();
if (ledPositions) {
for (auto i = 0; i < ledPositions->numberOfLed; i++) {
auto ledId = ledPositions->pLedPosition[i].ledId;
if (checkColor) {
CorsairLedColor testColor{ ledId };
CorsairGetLedsColors(1, &testColor);
if (testColor.r == r && testColor.g == g && testColor.b == b) {
colorsVector.push_back(testColor);
}
}
else {
colorsVector.push_back(CorsairLedColor{ ledId, colors[0], colors[1], colors[2] });
}
}
}
return colorsVector;
}
std::vector<CorsairLedColor> getBoardColors(int area) { // 0 - Whole board 1 - First character 2 - second character 3 - All non active keys
auto bgColors = mwReference->currentbgColors();
switch (area) {
case 0:
{
return getAvailableKeys(false, NULL, NULL, NULL); //Return all board keys
}
case 1:
{
//return all keys in area one as defined at top of file
std::vector<CorsairLedColor> areaKeys;
for (auto &ledId : AREA_ONE) {
areaKeys.push_back(CorsairLedColor{ ledId, bgColors[0], bgColors[1], bgColors[2] });
}
return areaKeys;
}
case 2:
{
//return all keys in area two as defined at top of file
std::vector<CorsairLedColor> areaKeys;
for (auto &ledId : AREA_TWO) {
areaKeys.push_back(CorsairLedColor{ ledId, bgColors[0], bgColors[1], bgColors[2] });
}
return areaKeys;
}
case 3:
{
//Find all unlit up keys
std::vector<int> rgbValues = mwReference->currentColors();
std::vector<int> rgbBValues = mwReference->currentbgColors();
std::vector<CorsairLedColor> areaKeys;
auto litKeys = getAvailableKeys(true, rgbValues[0], rgbValues[1], rgbValues[2]);
auto allKeys = getBoardColors(0);
if (litKeys.empty()) {
return allKeys;
} else {
std::vector<CorsairLedId> litIds;
std::transform(litKeys.begin(), litKeys.end(), std::back_inserter(litIds), [](CorsairLedColor c) { return c.ledId; }); //Create vector of led ids from lit keys
for (auto& led : allKeys) { //Remove all keys in vector that are in the second sector as to prevent over translation
if (std::find(litIds.begin(), litIds.end(), led.ledId) != litIds.end()) { //Check if led ID is in lit up keys
}
else {
areaKeys.push_back(CorsairLedColor{led.ledId, rgbBValues[0], rgbBValues[1], rgbBValues[2]});
}
}
}
return areaKeys;
}
default:
throw std::runtime_error("Failed to find any keys to clear");
}
}
void ColorWindow::showWindow() {
// Show color changing window and set modality
setModal(true);
setSize(200, 200, this);
std::vector<int> colors;
if (forBackground) {
colors = mwReference->currentbgColors();
} else {
colors = mwReference->currentColors();
}
redLabel->setGeometry(55, 7, 40, 40);
redBox->setGeometry(95, 10, 50, 30);
redBox->setRange(0, 255);
redBox->setValue(colors[0]);
greenLabel->setGeometry(55, 50, 40, 30);
greenBox->setGeometry(95, 50, 50, 30);
greenBox->setRange(0, 255);
greenBox->setValue(colors[1]);
blueLabel->setGeometry(55, 90, 40, 30);
blueBox->setGeometry(95, 90, 50, 30);
blueBox->setRange(0, 255);
blueBox->setValue(colors[2]);
submitButton->setGeometry(0, 150, 200, 50);
if (forBackground) {
connect(submitButton, &QPushButton::pressed, mwReference, &MainWindow::changeBackgroundColor);
} else {
connect(submitButton, &QPushButton::pressed, mwReference, &MainWindow::changeColor);
}
show();
}
ColorWindow::ColorWindow(bool background)
: QDialog()
{
setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
forBackground = background;
}
ColorWindow::~ColorWindow() {
}
std::vector<int> MainWindow::currentColors() {
return std::vector<int>{r, g, b};
}
std::vector<int> MainWindow::currentbgColors() {
//Return current background colors
return std::vector<int>{bR, bG, bB};
}
int MainWindow::changeColor() {
//Changed classes color characters
r = changeColorWindow->redBox->value();
g = changeColorWindow->greenBox->value();
b = changeColorWindow->blueBox->value();
auto keys = getBoardColors(0);
CorsairSetLedsColors(static_cast<int>(keys.size()), keys.data());
changeColorWindow->hide();
return 1;
}
int MainWindow::changeBackgroundColor() {
//Change the classes background color properties
bR = changeBackgroundWindow->redBox->value();
bG = changeBackgroundWindow->greenBox->value();
bB = changeBackgroundWindow->blueBox->value();
auto keys = getBoardColors(0);
CorsairSetLedsColors(static_cast<int>(keys.size()), keys.data());
changeBackgroundWindow->hide();
return 1;
}
int MainWindow::lightKeys(char keyChar) {
//Set color for character light up
CorsairLedColor charColor;
charColor.r = r;
charColor.g = g;
charColor.b = b;
//Set background color
CorsairLedColor backColor;
backColor.r = bR;
backColor.g = bG;
backColor.b = bB;
auto keys = getBoardColors(2);
CorsairSetLedsColors(static_cast<int>(keys.size()), keys.data()); //Clear the second character from board
auto currentKeys = getAvailableKeys(true, r, g, b); //Get all lit up keys (should only be the first character)
if (currentKeys.empty()) {
}
else {
std::vector<CorsairLedColor> newKeys;
for (auto &led : currentKeys) { //Remove all keys in vector that are in the second sector as to prevent over translation
if (std::find(AREA_TWO.begin(), AREA_TWO.end(), led.ledId) != AREA_TWO.end()) {
}
else {
newKeys.push_back(led);
}
}
std::vector<CorsairLedColor> translatedKeys;
for (auto &ledColor : newKeys) { //Translate keys by a vector of 5
CorsairLedId newID = (CorsairLedId)((int)ledColor.ledId + 5);
translatedKeys.push_back(CorsairLedColor{ newID, r, g, b });
}
auto keys = getBoardColors(0);
CorsairSetLedsColors(static_cast<int>(keys.size()), keys.data()); //Clear board
CorsairSetLedsColors(static_cast<int>(translatedKeys.size()), translatedKeys.data()); //Light translated keys
std::this_thread::sleep_for(std::chrono::milliseconds(35)); //Necessary to allow program to cacth up with new lit up keys
}
auto keysOne = getBoardColors(1);
CorsairSetLedsColors(static_cast<int>(keysOne.size()), keysOne.data()); //Remove old char
std::vector<CorsairLedColor> litKeys;
auto newKeys = getCharLights(keyChar, charColor);
CorsairSetLedsColors(static_cast<int>(newKeys.size()), newKeys.data()); //Light new character key
std::this_thread::sleep_for(std::chrono::milliseconds(35)); //Neccessary to allow the getBoardColors function to catch up with lit up keys
auto unusedKeys = getBoardColors(3);
CorsairSetLedsColors(static_cast<int>(unusedKeys.size()), unusedKeys.data()); //Set lights for all unlit keys
return 1;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
this->setWindowTitle("See It Corsair");
mwReference = this;
CorsairPerformProtocolHandshake(); //Corsair iCue initialisation
if (const auto error = CorsairGetLastError()) { //Check for corsair initialisation error
std::cout << "Handshake failed: " << toString(error) << "\nPress any key to quit." << std::endl;
getchar();
QCoreApplication::quit();
}
auto colorsVector = getBoardColors(0); // Clear board on start up
if (colorsVector.empty()) { //Check keys are available
std::runtime_error("No keys available on keyboard"); //Quit if no keys can be found
QCoreApplication::quit();
}
CorsairSetLedsColors(static_cast<int>(colorsVector.size()), colorsVector.data()); //Clear board
setSize(300, 100, this); //Scale window
QPushButton* changeColorButton = new QPushButton("Change Light Color", this);
QPushButton* changeBackgroundButton = new QPushButton("Change Background Light Color", this);
changeColorButton->setGeometry(0, 0, 300, 50);
changeBackgroundButton->setGeometry(0, 50, 300, 50);
//Link buttons to change color functions
connect(changeColorButton, &QPushButton::pressed, changeColorWindow, &ColorWindow::showWindow);
connect(changeBackgroundButton, &QPushButton::pressed, changeBackgroundWindow, &ColorWindow::showWindow);
HHOOK hhklowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0); //Initialise the hook
}
MainWindow::~MainWindow()
{
UnhookWindowsHookEx(hhklowLevelKybd); //Unhook key hook
}