-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchroma.cpp
85 lines (66 loc) · 2.42 KB
/
chroma.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
#include <Python.h>
#include <Windows.h>
#include <tchar.h>
#include "RzChromaSDKDefines.h"
#include "RzChromaSDKTypes.h"
#include "RzErrors.h"
typedef RZRESULT (*INIT)(void);
typedef RZRESULT (*CREATEKEYBOARDEFFECT)(ChromaSDK::Keyboard::EFFECT_TYPE Effect, PRZPARAM pParam, RZEFFECTID *pEffectId);
typedef RZRESULT (*SETEFFECT)(RZEFFECTID EffectId);
HMODULE chromaSDKModule;
INIT Init;
CREATEKEYBOARDEFFECT CreateKeyboardEffect;
SETEFFECT SetEffect;
#define RANDOM_BYTE() (rand() % 255)
#define NORMAL_COLOR RGB(175, 215, 0)
#define INSERT_COLOR RGB(232, 0, 0)
void
FillEffectWithColor(ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE &Effect, COLORREF color) {
for (UINT row = 0; row < ChromaSDK::Keyboard::MAX_ROW; row++) {
for (UINT col = 0; col < ChromaSDK::Keyboard::MAX_COLUMN; col++) {
Effect.Color[row][col] = color;
}
}
}
static PyObject *
chroma_insertmode(PyObject *self, PyObject *args) {
ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE Effect = {};
FillEffectWithColor(Effect, INSERT_COLOR);
Effect.Color[HIBYTE(ChromaSDK::Keyboard::RZKEY_ESC)][LOBYTE(ChromaSDK::Keyboard::RZKEY_ESC)] = NORMAL_COLOR;
RZRESULT effectResult = CreateKeyboardEffect(ChromaSDK::Keyboard::CHROMA_CUSTOM, &Effect, NULL);
Py_RETURN_NONE;
}
static PyObject *
chroma_normalmode(PyObject *self, PyObject *args) {
ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE Effect = {};
FillEffectWithColor(Effect, NORMAL_COLOR);
Effect.Color[HIBYTE(ChromaSDK::Keyboard::RZKEY_I)][LOBYTE(ChromaSDK::Keyboard::RZKEY_I)] = INSERT_COLOR;
RZRESULT effectResult = CreateKeyboardEffect(ChromaSDK::Keyboard::CHROMA_CUSTOM, &Effect, NULL);
Py_RETURN_NONE;
}
static PyMethodDef ChromaMethods[] = {
{ "insertmode", chroma_insertmode, METH_VARARGS,
"Switch the keyboard to insert mode." },
{ "normalmode", chroma_normalmode, METH_VARARGS,
"Switch the keyboard to normal mode." },
{ NULL, NULL, 0, NULL }
};
static struct PyModuleDef chromamodule = {
PyModuleDef_HEAD_INIT,
"chroma",
NULL,
-1,
ChromaMethods
};
PyMODINIT_FUNC
PyInit_chroma(void)
{
// Load the chroma SDK and get the address of needed functions
chromaSDKModule = LoadLibrary(_T("RzChromaSDK.dll"));
Init = (INIT)GetProcAddress(chromaSDKModule, "Init");
CreateKeyboardEffect = (CREATEKEYBOARDEFFECT)GetProcAddress(chromaSDKModule, "CreateKeyboardEffect");
SetEffect = (SETEFFECT)GetProcAddress(chromaSDKModule, "SetEffect");
// Initialize the driver
Init();
return PyModule_Create(&chromamodule);
}