XTEST FakeInput request

This commit is contained in:
sidorares 2011-09-08 12:38:46 +10:00
parent 5e999c3446
commit 7158b5c59f
2 changed files with 59 additions and 0 deletions

44
lib/x11/ext/xtest.js Normal file
View file

@ -0,0 +1,44 @@
// http://www.x.org/releases/X11R7.6/doc/xextproto/xtest.pdf
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('XTEST', function(ext) {
if (!ext.present)
callback(new Error('extension not available'));
ext.QueryVersion = function(clientMaj, clientMin, callback)
{
X.seq_num++;
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('LL');
return res;
},
callback
];
X.pack_stream.flush();
}
ext.KeyPress = 2;
ext.KeyRelease = 3;
ext.ButtonPress = 4;
ext.ButtonRelease = 5;
ext.MotionNotify = 6;
ext.FakeInput = function( type, keycode, time, wid, x, y )
{
X.seq_num++;
console.log([X.seq_num, 'CCSCCxxLLxxxxxxxxssxxxxxxxx', [ext.majorOpcode, 2, 9, type, keycode, time, wid, x, y]]);
X.pack_stream.pack('CCSCCxxLLxxxxxxxxssxxxxxxxx', [ext.majorOpcode, 2, 9, type, keycode, time, wid, x, y]);
X.pack_stream.flush();
}
callback(ext);
});
}

15
test/xtesttest.js Normal file
View file

@ -0,0 +1,15 @@
var x11 = require('../lib/x11');
var xclient = x11.createClient(function(display) {
var X = display.client;
var root = display.screen[0].root;
display.client.require('xtest', function(Test) {
console.log(Test);
setInterval(function() {
Test.FakeInput(Test.KeyPress, 65, 0, root, 0, 0); // space
Test.FakeInput(Test.KeyRelease, 65, 0, root, 0, 0); // space
console.log('click');
}, 1000);
});
display.client.on('error', function(err) { console.log(err); });
});