Skip to content

Commit dc6e0f8

Browse files
Add suinput_emit_combo()
1 parent e955d3b commit dc6e0f8

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/suinput.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ int suinput_emit_click(const int uinput_fd, const uint16_t key_code)
6060
return suinput_emit(uinput_fd, EV_KEY, key_code, 0);
6161
}
6262

63+
int suinput_emit_combo(const int uinput_fd, const uint16_t *const key_codes,
64+
const size_t len)
65+
{
66+
int retval = 0;
67+
size_t i;
68+
69+
for (i = 0; i < len; ++i) {
70+
if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 1) == -1) {
71+
retval = -1;
72+
break; /* The combination or the device is
73+
somehow broken: there's no sense to
74+
press any of the rest of the
75+
keys. It's like pressing physical keys
76+
one by one and then discovering that
77+
one of the keys required for this
78+
combination is missing or broken. */
79+
}
80+
}
81+
82+
/* Try to release every pressed key, no matter what. */
83+
while (i--) {
84+
if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 0) == -1) {
85+
retval = -1;
86+
}
87+
}
88+
89+
return retval;
90+
}
91+
6392
int suinput_syn(int uinput_fd)
6493
{
6594
return suinput_emit(uinput_fd, EV_SYN, SYN_REPORT, 0);

src/suinput.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code,
3636

3737
int suinput_emit_click(int uinput_fd, uint16_t key_code);
3838

39+
int suinput_emit_combo(int uinput_fd, const uint16_t *key_codes, size_t len);
40+
3941
int suinput_syn(int uinput_fd);
4042

4143
int suinput_destroy(int uinput_fd);

0 commit comments

Comments
 (0)