Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async GrabKey #120

Open
ewnd9 opened this issue Dec 21, 2015 · 11 comments
Open

Async GrabKey #120

ewnd9 opened this issue Dec 21, 2015 · 11 comments

Comments

@ewnd9
Copy link

ewnd9 commented Dec 21, 2015

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.

@sidorares
Copy link
Owner

could you post more code?

@ewnd9
Copy link
Author

ewnd9 commented Dec 21, 2015

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);
});

@sidorares
Copy link
Owner

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 )

@polpo
Copy link
Collaborator

polpo commented Dec 21, 2015

X.GrabKey is supposed to take 0 for GrabModeSync and 1 for GrabModeAsync, not false and true.

@polpo
Copy link
Collaborator

polpo commented Dec 21, 2015

Well, looks like Buffer converts false to 0 and true to 1, so that is not the issue.

@sidorares
Copy link
Owner

@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);
});

@ewnd9
Copy link
Author

ewnd9 commented Dec 21, 2015

No luck for me

@sidorares
Copy link
Owner

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

@ewnd9
Copy link
Author

ewnd9 commented Dec 21, 2015

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

@sidorares
Copy link
Owner

this seems like how it should work: because you grabbed space it was routed to root window instead of browser

@ewnd9
Copy link
Author

ewnd9 commented Dec 21, 2015

So, it is not possible to propagate events from cli? I'm trying to archive global keybindings for cli apps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants