forked from coolstar/crosecservice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crosecservice.cpp
71 lines (56 loc) · 1.75 KB
/
crosecservice.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
// crosecservice.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <Windows.h>
#include <cstdio>
#include <thread>
#include "croskbhid.h"
#include "KeyboardBacklight.h"
#include <SetupAPI.h>
BOOL isTabletConvertible;
void checkConvertible() {
isTabletConvertible = FALSE;
HDEVINFO hdevinfo = SetupDiGetClassDevsW(NULL, LR"(ACPI\GOOG0006)",
NULL, DIGCF_ALLCLASSES);
if (hdevinfo == INVALID_HANDLE_VALUE)
{
DWORD err = GetLastError();
return;
}
SP_DEVINFO_DATA devinfo;
devinfo.cbSize = sizeof(devinfo);
if (!SetupDiEnumDeviceInfo(hdevinfo, 0, &devinfo))
{
DWORD err = GetLastError();
return;
}
isTabletConvertible = TRUE;
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
checkConvertible();
pcroskbhid_client client = croskbhid_alloc();
BOOL connect = croskbhid_connect(client);
printf("Connected? %d\n", connect);
if (!connect) {
return 0;
}
KeyboardBacklight backlight(client);
CrosKBHIDRemapperMediaReport report = { 0 };
while (TRUE) {
croskbhid_read_keyboard(client, &report);
if (report.ReportID == REPORTID_MEDIA) {
if (report.ControlCode == 0)
continue;
if (report.ControlCode & CROSKBHID_KBLT_UP) {
backlight.BrightnessInc();
}
if (report.ControlCode & CROSKBHID_KBLT_DN) {
backlight.BrightnessDec();
}
if (report.ControlCode & CROSKBHID_KBLT_TOGGLE) {
backlight.SetBacklightEnabled(!backlight.GetBacklightEnabled());
}
}
}
croskbhid_disconnect(client);
}