diff --git a/examples/smoketest/getkeyboardmapping.js b/examples/smoketest/keyboard/getkeyboardmapping.js similarity index 55% rename from examples/smoketest/getkeyboardmapping.js rename to examples/smoketest/keyboard/getkeyboardmapping.js index 544d96e..ba89b50 100644 --- a/examples/smoketest/getkeyboardmapping.js +++ b/examples/smoketest/keyboard/getkeyboardmapping.js @@ -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); + } }); }); }); diff --git a/examples/smoketest/keyboard/package.json b/examples/smoketest/keyboard/package.json new file mode 100644 index 0000000..e1dcf41 --- /dev/null +++ b/examples/smoketest/keyboard/package.json @@ -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" +} diff --git a/lib/xcore.js b/lib/xcore.js index bcd4d5d..9194b55 100644 --- a/lib/xcore.js +++ b/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