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)
- 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
- UInput: Constructor can throw exception, leaving open a uinput fd HOT 19
- Incorrect device node found when creating more than one UInput device HOT 5
- Error 11 : write could not complete without blocking
- [SOLVED] Not getting any device when running as a daemon HOT 2
- `evdev` Not Correctly Capturing LEFTSHIFT Key Presses
- EvDev D-pad errors. HOT 4
- Many duplicate UInput force-feedback events with async HOT 1
- Unknown Files HOT 4
- sleep 1s after UI_DEV_CREATE
- Insufficient delay in UInput._find_device_fallback() HOT 11
- Mouse injection not working HOT 1
- Compilation error when installing evdev package in my hardware platform
- pip install does not use wheel, probably mangled filenames 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.