Repository navigation
Expand file tree
/
Copy path08_Keyboard_Minimal.cpp
More file actions
49 lines (48 loc) · 2 KB
/
Copy path08_Keyboard_Minimal.cpp
File metadata and controls
49 lines (48 loc) · 2 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
#include "Interceptor.h"
#include <iostream>
#include <system_error>
using namespace Interceptor;
int main() try {
std::cout
<< "Minimal example: capture inputs, change H to J, then forward them.\n"
"Run one example at a time as administrator. Close this window or press Ctrl+C to stop.\n"
<< std::flush;
// Check installation and initialize supported devices before capturing.
Get_Status();
const auto init = Init_AllDevices();
if (!init.ready) {
std::cerr << "Initialization failed. Error: " << init.error
<< ". Restart required: " << init.reboot_required << "\n";
return 1;
}
DWORD consoleMode = 0; // Console only: prevent text selection from blocking console writes.
if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &consoleMode)) {
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),
(consoleMode | ENABLE_EXTENDED_FLAGS) & ~ENABLE_QUICK_EDIT_MODE);
}
for (;;) {
// Receive: wait for input without polling.
auto inputs = Get_Input_With_Timeout(INFINITE);
for (auto& input : inputs) {
if (auto* key = input.Get<Keyboard_Input>()) {
if (!(key->stroke.flags & (KeyE0 | KeyE1)) && key->stroke.make_code == 0x23) {
key->stroke.make_code =
0x24; // H -> J; preserve the press/release flag and device.
}
}
}
// Forward: send all unblocked inputs, including other device types.
const auto sent = Send_Input(inputs);
if (!sent) {
throw std::system_error(sent.error, std::system_category(), "Send_Input");
}
}
} catch (const std::system_error& error) {
std::cerr
<< "Driver error: " << error.code().value()
<< ". Install this edition with InterceptorSetup.exe, restart if requested, and run as administrator.\n";
return 1;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}