rkeys
Version:
A platform for creating tablet/HTML5 virtual-keyboard apps to send keystrokes to remote X11
98 lines (97 loc) • 2.72 kB
JavaScript
// Generated by LiveScript 1.3.0
(function(){
var _, Cmd, Keyco, Keysim, D, delayTids, aurepTids;
_ = require('lodash');
Cmd = require('../../command');
Keyco = require('../../x11/keycode');
Keysim = require('../../x11/keysim');
D = require('../constants').directions;
delayTids = {};
aurepTids = {};
module.exports = function(arg$){
var command, direction, id, tid, seq, sequence;
command = arg$.command, direction = arg$.direction, id = arg$.id;
if (direction === D.UP) {
if (tid = aurepTids[id]) {
if (tid !== 'cancelled') {
clearTimeout(tid);
delete aurepTids[id];
}
} else if (delayTids[id]) {
aurepTids[id] = 'cancelled';
}
}
if (direction === D.DOWN) {
if (tid = aurepTids[id]) {
clearTimeout(tid);
delete aurepTids[id];
}
if (tid = delayTids[id]) {
clearTimeout(tid);
delete delayTids[id];
}
}
if (_.isArray(command)) {
command = command[direction];
} else {
if (direction !== D.DOWN) {
return;
}
}
command || (command = Cmd.applyAliases(id.replace(' ', 'space')));
seq = command.replace(/,/g, ' ').split(' ');
seq = _.map(seq, function(it){
var c;
if (Keyco.isKeysym(c = Cmd.getCommand(it))) {
return c;
} else {
return it;
}
});
applyNext(sequence = seq);
function applyNext(seq){
var ins, ms, tid, ref$;
if (!seq.length) {
delete aurepTids[id];
delete delayTids[id];
return;
}
if ((ins = seq[0]).length > 1 && (ms = _.parseInt(ins))) {
if (seq.length > 1) {
tid = setTimeout(applyNext, ms, seq.slice(1));
return delayTids[id] = tid;
}
if (aurepTids[id] === 'cancelled') {
return ref$ = aurepTids[id], delete aurepTids[id], ref$;
}
return aurepTids[id] = setTimeout(beginAutoRepeat, ms);
}
applyInstruction(ins);
return applyNext(seq.slice(1));
}
function beginAutoRepeat(){
delete aurepTids[id];
return applyNext(sequence);
}
return beginAutoRepeat;
};
function applyInstruction(it){
var chordKeys, i$, len$, k, results$ = [];
if (it[0] === '+') {
return Keysim.down(it.slice(1));
}
if (it[0] === '-') {
return Keysim.up(it.slice(1));
}
chordKeys = it.split('+');
for (i$ = 0, len$ = chordKeys.length; i$ < len$; ++i$) {
k = chordKeys[i$];
Keysim.down(k);
}
for (i$ = 0, len$ = chordKeys.length; i$ < len$; ++i$) {
k = chordKeys[i$];
results$.push(Keysim.up(k));
}
return results$;
}
}).call(this);