Why does Node hang when using deasync with x11 events?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 06:21:11

问题


I'm trying to use the node modules deasync and x11 to perform actions when certain keys are pressed.

When I use deasync inside a callback that has been initiated by a keypress deasync seems to be stuck in an endless loop. It works fine if I create a generic event myself.

Run the following script using xtrace to see that X11 does respond: xtrace -D :10 ./the-script

#!/usr/bin/env node

var deasync = require('deasync');
var x11 = require('x11');

var display = (deasync(x11.createClient)());
var client = display.client;

var getInputFocus = deasync(client.GetInputFocus)
    .bind(client);

var focus1 = getInputFocus();
console.log("getting focus here works:", focus1);

// grab the "1"-key - keyCode = 10
client.GrabKey(display.screen[0].root, 0, null, 10, 0, 1);

client.on('event', processKeyPressEvent);

// client.emit("event"); // works

function processKeyPressEvent(event) {
    console.log("can see this");
    var focus2 = getInputFocus(); // problem
    console.log("never get here");
}

Thanx for your help.

来源:https://stackoverflow.com/questions/30033837/why-does-node-hang-when-using-deasync-with-x11-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!