-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathkeyboard.cpp
40 lines (31 loc) · 825 Bytes
/
keyboard.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
#include "keyboard.h"
#include <stdexcept>
Keyboard::Keyboard()
: Device{L"\\\\?\\HID#VARIABLE_6&Col04#1"}
{}
void Keyboard::initialize()
{
if (isInitialized()) throw std::runtime_error{"ERROR_DOUBLE_INITIALIZATION"};
Device::initialize();
}
void Keyboard::type(BYTE keyCode)
{
BYTE keyCodes[6] = {KEY_NONE};
keyCodes[0] = keyCode;
sendKeyboardReport(keyCodes);
keyCodes[0] = KEY_NONE;
sendKeyboardReport(keyCodes);
}
void Keyboard::abort()
{
Device::abort();
}
void Keyboard::sendKeyboardReport(BYTE *keyCodes)
{
Report report;
report.reportId = REPORT_ID;
report.modifiers = m_modifiers;
report._reserved = 0x00;
std::memcpy(report.keyCodes, keyCodes, 6);
setOutputReport(&report, static_cast<DWORD>(sizeof(Report)));
}