fixed combo capture / reset
This commit is contained in:
parent
eccbc863b3
commit
c13b123423
4 changed files with 31 additions and 28 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
@ -10,7 +10,9 @@
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/ninwa.js",
|
"program": "${workspaceFolder}/ninwa.js",
|
||||||
"args": []
|
"args": [
|
||||||
|
"example_config.json"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@
|
||||||
"key": "key_f1",
|
"key": "key_f1",
|
||||||
"combo": [
|
"combo": [
|
||||||
"key_f2",
|
"key_f2",
|
||||||
"key_f4"
|
"key_f2"
|
||||||
],
|
],
|
||||||
"event": "EV_KEY",
|
"event": "EV_KEY",
|
||||||
"type": "keydown",
|
"type": "keydown",
|
||||||
|
@ -25,8 +25,8 @@
|
||||||
{
|
{
|
||||||
"key": "key_f1",
|
"key": "key_f1",
|
||||||
"combo": [
|
"combo": [
|
||||||
"key_f1",
|
"key_f2",
|
||||||
"key_f2"
|
"key_f3"
|
||||||
],
|
],
|
||||||
"event": "EV_KEY",
|
"event": "EV_KEY",
|
||||||
"type": "keydown",
|
"type": "keydown",
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
const comboConfig = require('../config.json').combos;
|
|
||||||
const commandConfig = require('../config.json').commands;
|
|
||||||
|
|
||||||
const LINE_START = 'Event: time';
|
const LINE_START = 'Event: time';
|
||||||
|
|
||||||
const ACTION_KEYUP = { id: 0, action: 'keyup' };
|
const ACTION_KEYUP = { id: 0, action: 'keyup' };
|
||||||
|
@ -19,10 +16,10 @@ class Keyfilter {
|
||||||
this.currentCombo = undefined;
|
this.currentCombo = undefined;
|
||||||
}
|
}
|
||||||
getCommand(command) {
|
getCommand(command) {
|
||||||
if (command === undefined || commandConfig === undefined) {
|
if (command === undefined || global.config?.commands === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = commandConfig[command];
|
const result = global.config.commands[command];
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -119,11 +116,22 @@ class Keyfilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isParsedEventValid(key, value, parsed) {
|
isParsedEventValid(key, value, parsed) {
|
||||||
let keyCheck = key === parsed.key;
|
if (value.event !== parsed.event || value.type.id !== parsed.type.id) {
|
||||||
if (value.combo !== undefined && value.combo.length > 0) {
|
return false;
|
||||||
keyCheck = key.includes(parsed.key);
|
|
||||||
}
|
}
|
||||||
return keyCheck && (value.event === undefined || value.event === parsed.event) && value.type.id === parsed.type.id;
|
if (value.combo === undefined || value.combo.length === 0) {
|
||||||
|
return key === parsed.key;
|
||||||
|
}
|
||||||
|
if (this.currentCombo === undefined) {
|
||||||
|
return key.startsWith(parsed.key);
|
||||||
|
}
|
||||||
|
for (let index = 0; index < this.currentCombo.possibilities.length; index++) {
|
||||||
|
if (this.currentCombo.possibilities[index].combo[0].toUpperCase() === parsed.key) {
|
||||||
|
this.resetCurrentCombo();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
setComboResult(result) {
|
setComboResult(result) {
|
||||||
if (result === undefined || this.currentCombo === undefined) {
|
if (result === undefined || this.currentCombo === undefined) {
|
||||||
|
@ -201,10 +209,6 @@ class Keyfilter {
|
||||||
if (this.currentCombo === undefined || this.currentCombo.type.id !== parsedEvent.type.id || this.currentCombo.event !== parsedEvent.event) {
|
if (this.currentCombo === undefined || this.currentCombo.type.id !== parsedEvent.type.id || this.currentCombo.event !== parsedEvent.event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if (this.currentCombo.done.includes(parsedEvent.key)) {
|
|
||||||
// parsedEvent.ignore = true;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
let possibilities = [];
|
let possibilities = [];
|
||||||
for (let index = 0; index < this.currentCombo.possibilities.length; index++) {
|
for (let index = 0; index < this.currentCombo.possibilities.length; index++) {
|
||||||
const possibility = this.currentCombo.possibilities[index];
|
const possibility = this.currentCombo.possibilities[index];
|
||||||
|
@ -236,13 +240,12 @@ class Keyfilter {
|
||||||
}
|
}
|
||||||
hasComboTimedOut() {
|
hasComboTimedOut() {
|
||||||
return false;
|
return false;
|
||||||
return comboConfig !== undefined &&
|
return global.config?.combos?.delay !== undefined &&
|
||||||
comboConfig.delay !== undefined &&
|
this.currentCombo?.timestamp !== undefined &&
|
||||||
this.currentCombo !== undefined &&
|
new Date().getTime() - this.currentCombo.timestamp > global.config?.combos?.dela;
|
||||||
this.currentCombo.timestamp !== undefined &&
|
|
||||||
new Date().getTime() - this.currentCombo.timestamp > comboConfig.delay;
|
|
||||||
}
|
}
|
||||||
resetCurrentCombo() {
|
resetCurrentCombo() {
|
||||||
|
console.debug('resetting current combo...');
|
||||||
this.currentCombo = undefined;
|
this.currentCombo = undefined;
|
||||||
}
|
}
|
||||||
isValid() {
|
isValid() {
|
||||||
|
|
10
ninwa.js
10
ninwa.js
|
@ -5,24 +5,22 @@ const packageJSON = require('./package.json');
|
||||||
|
|
||||||
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
||||||
|
|
||||||
let config;
|
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
handleInterrupts();
|
handleInterrupts();
|
||||||
try {
|
try {
|
||||||
let configFile = await util.getFileInfo(process.argv[2] || __dirname + '/config.json');
|
let configFile = await util.getFileInfo(process.argv[2] || __dirname + '/config.json');
|
||||||
config = require(configFile.path);
|
global.config = require(configFile.path);
|
||||||
config.path = config.path;
|
global.config.path = configFile.path;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.initialize(config.log.level, config.log.timestamp);
|
logger.initialize(global.config.log.level, global.config.log.timestamp);
|
||||||
logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
|
||||||
await watchers.initialize(config.watchers);
|
await watchers.initialize(global.config.watchers);
|
||||||
await watchers.start();
|
await watchers.start();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
|
Loading…
Reference in a new issue