我正在尝试使用节点模块deasync
和x11
来执行按下某些键时的操作。
当我在一个由keypress deasync启动的回调中使用deasync似乎陷入无限循环时。 如果我自己创建一个通用事件,它工作正常。
使用xtrace运行以下脚本以查看X11是否响应:
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求助。