entering text as key codes

This commit is contained in:
antelle 2021-01-30 21:34:08 +01:00
parent 8dc3a4b51f
commit 4449677e36
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
5 changed files with 50 additions and 20 deletions

View File

@ -74,11 +74,17 @@ class AutoTypeEmitter {
}
setMod(mod, enabled) {
// TODO: press the modifier
const nativeMod = ModMap[mod];
if (!nativeMod) {
return this.callback(`Bad modifier: ${mod}`);
}
NativeModules.kbdKeyMoveWithModifier(!!enabled, [nativeMod]).catch((e) => {
logger.error('Error moving modifier', mod, enabled ? 'down' : 'up', e);
});
if (enabled) {
this.mod[ModMap[mod]] = true;
this.mod[nativeMod] = true;
} else {
delete this.mod[ModMap[mod]];
delete this.mod[nativeMod];
}
}
@ -86,9 +92,9 @@ class AutoTypeEmitter {
if (!str) {
return this.withCallback(Promise.resolve());
}
const mod = Object.keys(this.mod);
if (mod.length) {
// TODO
const mods = Object.keys(this.mod);
if (mods.length) {
this.withCallback(NativeModules.kbdTextAsKeys(str, mods));
} else {
this.withCallback(NativeModules.kbdText(str));
}

View File

@ -230,6 +230,10 @@ if (Launcher) {
return this.call('kbdText', str);
},
kbdTextAsKeys(str, mods) {
return this.call('kbdTextAsKeys', str, mods);
},
kbdKeyPress(code, modifiers) {
return this.call('kbdKeyPress', code, modifiers);
},
@ -238,13 +242,9 @@ if (Launcher) {
return this.call('kbdShortcut', code, modifiers);
},
// kbdKeyMoveWithCode(down, code, modifiers) {
// return this.call('kbdKeyMoveWithCode', down, code, modifiers);
// },
//
// kbdKeyMoveWithModifier(down, modifiers) {
// return this.call('kbdKeyMoveWithModifier', down, modifiers);
// },
kbdKeyMoveWithModifier(down, modifiers) {
return this.call('kbdKeyMoveWithModifier', down, modifiers);
},
kbdKeyPressWithCharacter(character, code, modifiers) {
return this.call('kbdKeyPressWithCharacter', character, code, modifiers);

View File

@ -119,6 +119,10 @@ const messageHandlers = {
return getAutoType().text(str);
},
kbdTextAsKeys(str, mods) {
return kbdTextAsKeys(str, mods);
},
kbdKeyPress(code, modifiers) {
return getAutoType().keyPress(kbdKeyCode(code), kbdModifier(modifiers));
},
@ -127,10 +131,6 @@ const messageHandlers = {
return getAutoType().shortcut(kbdKeyCode(code));
},
kbdKeyMoveWithCode(down, code, modifiers) {
return getAutoType().keyMoveWithCode(down, kbdKeyCode(code), kbdModifier(modifiers));
},
kbdKeyMoveWithModifier(down, modifiers) {
return getAutoType().keyMoveWithModifier(down, kbdModifier(modifiers));
},
@ -209,6 +209,30 @@ function kbdModifier(modifiers) {
return modifier;
}
function kbdTextAsKeys(str, modifiers) {
const typer = getAutoType();
const modifier = kbdModifier(modifiers);
let ix = 0;
for (const kc of typer.osKeyCodesForChars(str)) {
const char = str[ix++];
let effectiveModifier = modifier;
if (kc?.modifier) {
typer.keyMoveWithModifier(true, kc.modifier);
effectiveModifier |= kc.modifier;
}
if (kc) {
typer.keyMoveWithCharacter(true, null, kc.code, effectiveModifier);
typer.keyMoveWithCharacter(false, null, kc.code, effectiveModifier);
} else {
typer.keyMoveWithCharacter(true, char, null, effectiveModifier);
typer.keyMoveWithCharacter(false, char, null, effectiveModifier);
}
if (kc?.modifier) {
typer.keyMoveWithModifier(false, kc.modifier);
}
}
}
function startListener() {
process.on('message', ({ callId, cmd, args }) => {
Promise.resolve()

4
package-lock.json generated
View File

@ -1982,8 +1982,8 @@
}
},
"@keeweb/keeweb-native-modules": {
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.7/keeweb-native-modules.tgz",
"integrity": "sha512-rIe5RAFSIW6kHZ2dsf3w5M+7OJxgG6lKMrYxd2nbV+4VJvKK1+Fu14X3jBwoMlSEkqeuyF+GXb78isu6X0hxIQ=="
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.9/keeweb-native-modules.tgz",
"integrity": "sha512-xKcm1X89LHQT7JzaYfUW4jIdA0pYREZQ0JDw8ORfIKPhifJF8j7q5xs9Iwu3yEJv7pFNfQIkLRh6pJL80aTkkA=="
},
"@sindresorhus/is": {
"version": "0.14.0",

View File

@ -16,7 +16,7 @@
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
"@babel/preset-env": "^7.12.7",
"@fortawesome/fontawesome-free": "^5.15.1",
"@keeweb/keeweb-native-modules": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.7/keeweb-native-modules.tgz",
"@keeweb/keeweb-native-modules": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.9/keeweb-native-modules.tgz",
"adm-zip": "^0.5.1",
"argon2-browser": "1.15.2",
"autoprefixer": "^10.0.4",