-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_echo.c
49 lines (39 loc) · 1.19 KB
/
test_echo.c
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 "src/libvinput.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
EventListener g_listener;
EventEmulator g_emulator;
bool g_is_typing;
void keyboard_callback(KeyboardEvent evt)
{
if (g_is_typing) return;
if (!isprint(evt.keychar)) return;
if (!evt.pressed) return;
printf("got key press/release: %c\n", evt.keychar);
g_is_typing = true;
EventEmulator_typec(&g_emulator, evt.keychar);
g_is_typing = false;
}
int main(void)
{
uint32_t version = VInput_version();
printf("VInput version: %d.%d.%d\n", VINPUT_VERSION_MAJOR(version),
VINPUT_VERSION_MINOR(version), VINPUT_VERSION_PATCH(version));
VInputError err = EventListener2_create(&g_listener, true, false, false);
if (err) {
fprintf(stderr, "ERROR: Failed to create keyboard listener! Error: %s\n",
VInput_error_get_message(err));
}
err = EventEmulator_create(&g_emulator);
if (err) {
fprintf(stderr, "ERROR: Failed to start event emulator! Error: %s\n",
VInput_error_get_message(err));
return 1;
}
err = EventListener2_start(&g_listener, &keyboard_callback, NULL, NULL);
if (err) {
fprintf(stderr, "ERROR: Failed to start keyboard listener! Error: %s\n",
VInput_error_get_message(err));
}
}