From 8b2bdb28bd39217196575a4fe4fe86e30fb3b2fa Mon Sep 17 00:00:00 2001 From: Johannes Bensmann Date: Sun, 9 Feb 2020 13:29:41 +0100 Subject: query state of all keys at start --- Makefile | 2 +- xmouseless.c | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 621ed22..f8e8698 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # xmouseless -VERSION = 0.1.0 +VERSION = 0.1.1 CC = /usr/bin/gcc CFLAGS = -Wall -g LDFLAGS = -lX11 -lXtst -lpthread diff --git a/xmouseless.c b/xmouseless.c index a187890..e7dfa1f 100644 --- a/xmouseless.c +++ b/xmouseless.c @@ -71,7 +71,7 @@ void move_relative(float x, float y); void click(unsigned int button, Bool is_press); void click_full(unsigned int button); void scroll(float x, float y); -void handle_key(XKeyEvent event); +void handle_key(KeyCode keycode, Bool is_press); void init_x(); void close_x(); @@ -178,13 +178,11 @@ void *move_forever(void *val) { } } -void handle_key(XKeyEvent event) { +void handle_key(KeyCode keycode, Bool is_press) { unsigned int i; KeySym keysym; - Bool is_press; - keysym = XkbKeycodeToKeysym(dpy, event.keycode, 0, 0); - is_press = (event.type == KeyPress); + keysym = XkbKeycodeToKeysym(dpy, keycode, 0, 0); /* move bindings */ for (i = 0; i < LENGTH(move_bindings); i++) { @@ -243,8 +241,9 @@ void handle_key(XKeyEvent event) { } int main () { + char keys_return[32]; int rc; - XEvent event; + int i, j; init_x(); @@ -265,14 +264,26 @@ int main () { return EXIT_FAILURE; } + /* get the initial state of all keys */ + XQueryKeymap(dpy, keys_return); + for (i = 0; i < 32; i++) { + for (j = 0; j < 8; j++) { + if (keys_return[i] & (1<