Repository navigation
Expand file tree
/
Copy path08_Keyboard_Minimal.cpp
More file actions
35 lines (34 loc) · 1.99 KB
/
Copy path08_Keyboard_Minimal.cpp
File metadata and controls
35 lines (34 loc) · 1.99 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
#include "Interceptor.h"
#include <iostream>
#include <string_view>
#include <system_error>
using namespace Interceptor;
int main(int argc, char** argv) 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;
if (argc == 2 && std::string_view(argv[1]) == "--help") return 0;
if (argc != 1) throw std::invalid_argument("Run without arguments, or use --help.");
Get_Status(); // Read-only check: this edition's installed driver must respond.
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; // Avoid Quick Edit pausing capture in the classic Windows console.
if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &consoleMode))
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), (consoleMode | ENABLE_EXTENDED_FLAGS) & ~ENABLE_QUICK_EDIT_MODE);
for (;;) {
auto inputs = Get_Input_With_Timeout(INFINITE); // Wait for a batch; the library owns the capture.
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.
const auto sent = Send_Input(inputs); // Forward every unblocked entry, including other device types.
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;
}