Async GrabKey
Opened this issue · 11 comments
I am trying something like X.GrabKey(root, 0, 0, 65, false, true);
to capture space keypresses. How can I propagate keypress event to all system? Right now script is blocking space key, so the system doesn't see it.
could you post more code?
Sorry, should have done it in the first message
var x11 = require('x11');
x11.createClient(function(error, display) {
var X = display.client;
var root = display.screen[0].root;
var space = 65;
var pointerMode = false;
var keyboardMode = true;
X.GrabKey(root, 0, 0, space, pointerMode, keyboardMode);
}).on('event', function(event) {
console.log(event);
});
I'm not sure that just by grabbing keyboard you are selection corresponding event mask. Try to add ChangeAttribute on root window with corresponding key event mask. ( I'll post code once I have example working )
X.GrabKey is supposed to take 0 for GrabModeSync and 1 for GrabModeAsync, not false and true.
Well, looks like Buffer converts false to 0 and true to 1, so that is not the issue.
@ewnd9 this code works for me ( I have 57 as key code for space )
var x11 = require('./');
x11.createClient(function(error, display) {
var X = display.client;
var root = display.screen[0].root;
var space = 57;
var pointerMode = false;
var keyboardMode = true;
X.GrabKey(root, 0, 0, space, pointerMode, keyboardMode);
X.ChangeWindowAttributes(root, { eventMask: x11.eventMask.KeyPress });
}).on('event', function(event) {
console.log(event);
});
No luck for me
how do you test it? Do you get events printed when focus is on root window? I used Xephyr for test to avoid interaction with window manager
I ran directly in terminal, events are always printed. Example: I start script and when I print in browser / other terminal sequence "a" "space" "b" I get "ab" in input
this seems like how it should work: because you grabbed space it was routed to root window instead of browser
So, it is not possible to propagate events from cli? I'm trying to archive global keybindings for cli apps