mirror of
https://github.com/danbulant/node-x11
synced 2026-06-19 06:31:22 +00:00
add MappingNotify event
This commit is contained in:
parent
66e94be8de
commit
421261aaac
3 changed files with 37 additions and 5 deletions
|
|
@ -1,4 +1,6 @@
|
|||
var x11 = require('../../lib');
|
||||
var x11 = require('../../../lib');
|
||||
var keysym = require('keysym');
|
||||
|
||||
|
||||
var ks = x11.keySyms;
|
||||
var ks2Name = {};
|
||||
|
|
@ -16,7 +18,7 @@ x11.createClient(function(err, display) {
|
|||
var name = kk2Name[i+min] = [];
|
||||
var sublist = list[i];
|
||||
for (var j =0; j < sublist.length; ++j)
|
||||
name.push(ks2Name[sublist[j]]);
|
||||
name.push([ks2Name[sublist[j]], sublist[j]]);
|
||||
}
|
||||
|
||||
var root = display.screen[0].root;
|
||||
|
|
@ -27,7 +29,19 @@ x11.createClient(function(err, display) {
|
|||
X.MapWindow(wid);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
console.log([ev.keycode, kk2Name[ev.keycode]]);
|
||||
console.log(ev.type);
|
||||
console.log(ev);
|
||||
//console.log([ev.keycode, kk2Name[ev.keycode], keysym.fromKeysym(kk2Name[ev.keycode][0][1])]);
|
||||
var shift = ev.buttons & 1;
|
||||
var keySyms = kk2Name[ev.keycode];
|
||||
if (keySyms) {
|
||||
var codePoint = keysym.fromKeysym(keySyms[shift ? 1 : 0][1]).unicode;
|
||||
if (codePoint == 13)
|
||||
codePoint = 10;
|
||||
if (codePoint != 0)
|
||||
process.stdout.write(String.fromCharCode(codePoint));
|
||||
//console.log('\n', codePoint);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
11
examples/smoketest/keyboard/package.json
Normal file
11
examples/smoketest/keyboard/package.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "keyboard",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "getkeyboardmapping.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
11
lib/xcore.js
11
lib/xcore.js
|
|
@ -244,7 +244,7 @@ XClient.prototype.AllocID = function()
|
|||
|
||||
|
||||
// TODO: move core events unpackers to corereqs.js
|
||||
XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
||||
XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||
{
|
||||
var event = {}; // TODO: constructor & base functions
|
||||
// Remove the most significant bit. See Chapter 1, Event Format section in X11 protocol
|
||||
|
|
@ -398,6 +398,13 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
|||
event.type = raw.readUInt32LE(0);
|
||||
var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC';
|
||||
event.data = raw.unpack(format, 4);
|
||||
} else if (type == 34) {
|
||||
event.name = 'MappingNotify';
|
||||
event.request = headerBuf[4];
|
||||
event.firstKeyCode = headerBuf[5];
|
||||
event.count = headerBuf[6];
|
||||
console.log(values);
|
||||
console.log(raw);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
|
@ -458,7 +465,7 @@ XClient.prototype.expectReplyHeader = function()
|
|||
client.pack_stream.get(24, function(buf) {
|
||||
var extra = res[3];
|
||||
var code = res[1];
|
||||
var ev = client.unpackEvent(type, seq_num, extra, code, buf);
|
||||
var ev = client.unpackEvent(type, seq_num, extra, code, buf, headerBuf);
|
||||
|
||||
// raw event 32-bytes packet (primarily for use in SendEvent);
|
||||
// TODO: Event::pack based on event parameters, inverse to unpackEvent
|
||||
|
|
|
|||
Loading…
Reference in a new issue