Comments (3)
Take this with a grain of salt - I think this happens because your terminal receives a key press event (1), but never the corresponding key release (2) event. The same would happen even if you wrote your program in C:
#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <poll.h>
int main(int argc, char *argv[])
{
int fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
struct pollfd fds = {fd, POLLIN, POLLIN};
struct input_event event;
char cmd[50];
sprintf(cmd, "sleep 5 && kill %d &", (int)getpid());
system(cmd); // just in case
while (poll(&fds, 1, -1)) {
int n = read(fd, &event, sizeof(event));
if (event.type == EV_KEY) {
if ((event.code == KEY_LEFTCTRL) && (event.value == 1))
ioctl(fd, EVIOCGRAB, 1);
if ((event.code == KEY_LEFTCTRL) && (event.value == 0))
ioctl(fd, EVIOCGRAB, 0);
}
return 0;
}
You can inject a few events into the input stream to prevent this:
ui = UInput()
for ev in dev.read_loop():
if ev.code == KEY_LEFTCTRL and ev.value == 1:
ui.write_event(ev)
ui.write(EV_KEY, KEY_LEFTCTRL, 0)
ui.syn
dev.grab()
...
from python-evdev.
Actually, that is what I did in the first place, just removed the ui stuff for the sake of clarity in the example.
You see, the odd thing is, the ungrab command seems to be executed all right: βUngrabβ is printed and if you try to ungrab it again (e.g. after the loop), you get an error (which means the device is already ungrabbed). I believe, the problem is in the grab/ungrab itself. The release event is also caught (just printing all the events proves it).
I will try to follow your advice though. Thanks a lot for fast and useful comments!
from python-evdev.
Thanks a million!
Even though I don't get why injecting a 'release' event right after a 'press' one would help, it did :-)
Thanks for assistance, and thanks for the module, great work that saved my day.
from python-evdev.
Related Issues (20)
- Changelog does not include any mention of 1.6 release
- Providing the package as a wheel HOT 20
- Surface Dial Haptics HOT 3
- Using evdev with international/non-US keyboard layouts? HOT 5
- New example - opentrack head-tracking to mouse events
- Unable to install via pip on Arch Linux/Python 3.10.9 HOT 2
- Edev fails to install on ubuntu 18.04 with pip2 HOT 4
- Wayland behavior different from X11? HOT 9
- Failures in output without adding sleep delays HOT 10
- Upgrade from 1.6.0 to 1.6.1 fails HOT 1
- error: command 'gcc-11' failed: No such file or directory HOT 1
- Documentation fix HOT 3
- OSError: [Errno 19] No such device: '/dev/input/event0', after unplugging event0
- Enforce key repeat by kernel HOT 2
- RFE: please restart making github releases
- Cannot open joystick (js0) device
- Cannot open input device HOT 1
- Forwarding EV_UINPUT events for FF is difficult due to undocumented behaviour HOT 4
- evdev not working for Wayland
- timeout read_loop? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-evdev.