Read physical state of keyboard modifiers in Linux (preferably in C or C++)
0
votes
0
answers
623
views
Is there a way to programmatically read, detect or get notified about the **actual physical state** of a modifier key, **without requiring root level access** rights?
I tried X11, XCB and XKB, but their event driven approach only registers modifier changes after the modifier key either has been released physically or been otherwise used (e.g. during mouse click).
I'm looking for a way to asynchronously be able to read out e.g. the SHIFT key pressed/released state, without having to wait for a "consuming" next event to happen. If X11/XCB/XKB does not allow this, I would also consider going into the HID direction, but before doing this, I wanted to clarify, if I didn't overlook something simple like a non-blocking modifier event mode or something similar which just simply needs to be switched on.
**EDIT (2023-09-30)**:
I now also took a look at
XInput
v2 and its raw key input support, but it did not help much. The event processing apparently already inherits this behaviour from driver level.
The next step was to investigate the output from evtest
, and this seems to confirm the theory, that it is not even possible to asynchronously see the physical state, if the driver layer does not process/communicate the related state change synchronously.
This is a copy from the terminal output, where you can see that the modifier press/release is just some milliseconds apart, while actually they we
re pressed for longer than that:
Testing ... (interrupt to exit)
Event: time 1696090563.122466, type 4 (EV_MSC), code 4 (MSC_SCAN), value 1c
Event: time 1696090563.122466, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0
Event: time 1696090563.122466, -------------- SYN_REPORT ------------
Event: time 1696090567.475603, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090567.475603, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1
Event: time 1696090567.475603, -------------- SYN_REPORT ------------
Event: time 1696090567.487761, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090567.487761, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 0
Event: time 1696090567.487761, -------------- SYN_REPORT ------------
Event: time 1696090570.051134, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090570.051134, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1
Event: time 1696090570.051134, -------------- SYN_REPORT ------------
Event: time 1696090570.062911, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090570.062911, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 0
Event: time 1696090570.062911, -------------- SYN_REPORT ------------
Event: time 1696090574.108130, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090574.108130, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1
Event: time 1696090574.108130, -------------- SYN_REPORT ------------
Event: time 1696090574.119016, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1696090574.119016, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 0
Event: time 1696090574.119016, -------------- SYN_REPORT ------------
Event: time 1696090576.276169, type 4 (EV_MSC), code 4 (MSC_SCAN), value 1d
Event: time 1696090576.276169, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 1
Event: time 1696090576.276169, -------------- SYN_REPORT ------------
Event: time 1696090576.288810, type 4 (EV_MSC), code 4 (MSC_SCAN), value 1d
Event: time 1696090576.288810, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 0
Event: time 1696090576.288810, -------------- SYN_REPORT ------------
Event: time 1696090577.396269, type 4 (EV_MSC), code 4 (MSC_SCAN), value 38
Event: time 1696090577.396269, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 1
Event: time 1696090577.396269, -------------- SYN_REPORT ------------
Event: time 1696090577.407817, type 4 (EV_MSC), code 4 (MSC_SCAN), value 38
Event: time 1696090577.407817, type 1 (EV_KEY), code 56 (KEY_LEFTALT), value 0
Event: time 1696090577.407817, -------------- SYN_REPORT ------------
Asked by psq3000
(1 rep)
Sep 28, 2023, 02:21 PM
Last activity: Sep 30, 2023, 04:39 PM
Last activity: Sep 30, 2023, 04:39 PM