var spawn = require('cross-spawn');
var MPR121 = require('node-picap');
var mpr121;

var p1Left = 4;
var p1Right = 5;
var p1Up = 6;
var p1Down = 7;

var p2Left = 8;
var p2Right = 9;
var p2Up = 10;
var p2Down = 11;

var p1Start = 12;
var p1Back = 13;
// correct address for the Pi Cap - other boards may vary
mpr121 = new MPR121('0x5C');
mpr121.setTouchThreshold(40);
mpr121.setReleaseThreshold(20);

mpr121.on('data', function(data) {
  var keys = [];
  data.forEach(function(electrode, i) {
    if (electrode.isNewTouch) {
      spawn.sync('echo -ne "\\0\\0\\4\\0\\0\\0\\0\\0" > /dev/hidg0', [], { stdio: 'inherit' });
    }
  });
});

process.on('SIGINT', function () {
  process.exit(0);
});

@@ -528,53 +528,912 @@
    s
-pawn.sync('echo -ne %22%5C%5C0%5C%5C0%5C%5C4%5C%5C0%5C%5C0%5C%5C0%5C%5C0%5C%5C0
+witch(i) %7B%0A        case 0:%0A          keys.push(p1Left);%0A          break;%0A        case 1:%0A          keys.push(p1Right);%0A          break;%0A        case 2:%0A          keys.push(p1Up);%0A          break;%0A        case 3:%0A          keys.push(p1Down);%0A          break;%0A        case 4:%0A          keys.push(p2Left);%0A          break;%0A        case 5:%0A          keys.push(p2Right);%0A          break;%0A        case 6:%0A          keys.push(p2Up);%0A          break;%0A        case 7:%0A          keys.push(p2Down);%0A          break;%0A        case 8:%0A          keys.push(p2Up);%0A          break;%0A        case 9:%0A          keys.push(p1Start);%0A          break;%0A        case 10:%0A          keys.push(p1Back);%0A          break;%0A      %7D%0A    %7D%0A  %7D);%0A  keystroke = %22%5C%5C0%5C%5C0%22;%0A  keys.forEach(function(key) %7B%0A    keystroke += %22%5C%5C%22 + key;%0A  %7D);%0A  while(keystroke.length != 24) %7B%0A    keystroke += %22%5C%5C0%22;%0A  %7D%0A  spawn.sync('echo -ne %22' + keystroke + '
 %22 %3E 
@@ -1472,28 +1472,16 @@
 it' %7D);%0A
-    %7D%0A  %7D);%0A
 %7D);%0A%0Apro

Implement (as of yet untested) logic