Speed up release of keys in fast inject mode

This commit is contained in:
Federico Terzi 2020-04-18 18:19:20 +02:00
parent 7da2678947
commit 761758b136

View File

@ -303,13 +303,35 @@ void send_enter() {
xdo_send_keysequence_window(xdo_context, CURRENTWINDOW, "Return", 1000);
}
void fast_release_all_keys() {
Window focused;
int revert_to;
XGetInputFocus(xdo_context->xdpy, &focused, &revert_to);
char keys[32];
XQueryKeymap(xdo_context->xdpy, keys); // Get the current status of the keyboard
for (int i = 0; i<32; i++) {
// Only those that show a keypress should be changed
if (keys[i] != 0) {
for (int k = 0; k<8; k++) {
if ((keys[i] & (1 << k)) != 0) { // Bit by bit check
int key_code = i*8 + k;
fast_send_event(xdo_context, focused, keycode, 0);
}
}
}
}
XFlush(xdo_context->xdpy);
}
void fast_send_string(const char * string) {
// It may happen that when an expansion is triggered, some keys are still pressed.
// This causes a problem if the expanded match contains that character, as the injection
// will not be able to register that keypress (as it is already pressed).
// To solve the problem, before an expansion we get which keys are currently pressed
// and inject a key_release event so that they can be further registered.
release_all_keys();
fast_release_all_keys();
Window focused;
int revert_to;