mirror of https://github.com/keeweb/keeweb.git
entering text as key codes
This commit is contained in:
parent
8dc3a4b51f
commit
4449677e36
|
@ -74,11 +74,17 @@ class AutoTypeEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
setMod(mod, enabled) {
|
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) {
|
if (enabled) {
|
||||||
this.mod[ModMap[mod]] = true;
|
this.mod[nativeMod] = true;
|
||||||
} else {
|
} else {
|
||||||
delete this.mod[ModMap[mod]];
|
delete this.mod[nativeMod];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +92,9 @@ class AutoTypeEmitter {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return this.withCallback(Promise.resolve());
|
return this.withCallback(Promise.resolve());
|
||||||
}
|
}
|
||||||
const mod = Object.keys(this.mod);
|
const mods = Object.keys(this.mod);
|
||||||
if (mod.length) {
|
if (mods.length) {
|
||||||
// TODO
|
this.withCallback(NativeModules.kbdTextAsKeys(str, mods));
|
||||||
} else {
|
} else {
|
||||||
this.withCallback(NativeModules.kbdText(str));
|
this.withCallback(NativeModules.kbdText(str));
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,6 +230,10 @@ if (Launcher) {
|
||||||
return this.call('kbdText', str);
|
return this.call('kbdText', str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
kbdTextAsKeys(str, mods) {
|
||||||
|
return this.call('kbdTextAsKeys', str, mods);
|
||||||
|
},
|
||||||
|
|
||||||
kbdKeyPress(code, modifiers) {
|
kbdKeyPress(code, modifiers) {
|
||||||
return this.call('kbdKeyPress', code, modifiers);
|
return this.call('kbdKeyPress', code, modifiers);
|
||||||
},
|
},
|
||||||
|
@ -238,13 +242,9 @@ if (Launcher) {
|
||||||
return this.call('kbdShortcut', code, modifiers);
|
return this.call('kbdShortcut', code, modifiers);
|
||||||
},
|
},
|
||||||
|
|
||||||
// kbdKeyMoveWithCode(down, code, modifiers) {
|
kbdKeyMoveWithModifier(down, modifiers) {
|
||||||
// return this.call('kbdKeyMoveWithCode', down, code, modifiers);
|
return this.call('kbdKeyMoveWithModifier', down, modifiers);
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// kbdKeyMoveWithModifier(down, modifiers) {
|
|
||||||
// return this.call('kbdKeyMoveWithModifier', down, modifiers);
|
|
||||||
// },
|
|
||||||
|
|
||||||
kbdKeyPressWithCharacter(character, code, modifiers) {
|
kbdKeyPressWithCharacter(character, code, modifiers) {
|
||||||
return this.call('kbdKeyPressWithCharacter', character, code, modifiers);
|
return this.call('kbdKeyPressWithCharacter', character, code, modifiers);
|
||||||
|
|
|
@ -119,6 +119,10 @@ const messageHandlers = {
|
||||||
return getAutoType().text(str);
|
return getAutoType().text(str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
kbdTextAsKeys(str, mods) {
|
||||||
|
return kbdTextAsKeys(str, mods);
|
||||||
|
},
|
||||||
|
|
||||||
kbdKeyPress(code, modifiers) {
|
kbdKeyPress(code, modifiers) {
|
||||||
return getAutoType().keyPress(kbdKeyCode(code), kbdModifier(modifiers));
|
return getAutoType().keyPress(kbdKeyCode(code), kbdModifier(modifiers));
|
||||||
},
|
},
|
||||||
|
@ -127,10 +131,6 @@ const messageHandlers = {
|
||||||
return getAutoType().shortcut(kbdKeyCode(code));
|
return getAutoType().shortcut(kbdKeyCode(code));
|
||||||
},
|
},
|
||||||
|
|
||||||
kbdKeyMoveWithCode(down, code, modifiers) {
|
|
||||||
return getAutoType().keyMoveWithCode(down, kbdKeyCode(code), kbdModifier(modifiers));
|
|
||||||
},
|
|
||||||
|
|
||||||
kbdKeyMoveWithModifier(down, modifiers) {
|
kbdKeyMoveWithModifier(down, modifiers) {
|
||||||
return getAutoType().keyMoveWithModifier(down, kbdModifier(modifiers));
|
return getAutoType().keyMoveWithModifier(down, kbdModifier(modifiers));
|
||||||
},
|
},
|
||||||
|
@ -209,6 +209,30 @@ function kbdModifier(modifiers) {
|
||||||
return modifier;
|
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() {
|
function startListener() {
|
||||||
process.on('message', ({ callId, cmd, args }) => {
|
process.on('message', ({ callId, cmd, args }) => {
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
|
|
|
@ -1982,8 +1982,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@keeweb/keeweb-native-modules": {
|
"@keeweb/keeweb-native-modules": {
|
||||||
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.7/keeweb-native-modules.tgz",
|
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.9/keeweb-native-modules.tgz",
|
||||||
"integrity": "sha512-rIe5RAFSIW6kHZ2dsf3w5M+7OJxgG6lKMrYxd2nbV+4VJvKK1+Fu14X3jBwoMlSEkqeuyF+GXb78isu6X0hxIQ=="
|
"integrity": "sha512-xKcm1X89LHQT7JzaYfUW4jIdA0pYREZQ0JDw8ORfIKPhifJF8j7q5xs9Iwu3yEJv7pFNfQIkLRh6pJL80aTkkA=="
|
||||||
},
|
},
|
||||||
"@sindresorhus/is": {
|
"@sindresorhus/is": {
|
||||||
"version": "0.14.0",
|
"version": "0.14.0",
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
|
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
|
||||||
"@babel/preset-env": "^7.12.7",
|
"@babel/preset-env": "^7.12.7",
|
||||||
"@fortawesome/fontawesome-free": "^5.15.1",
|
"@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",
|
"adm-zip": "^0.5.1",
|
||||||
"argon2-browser": "1.15.2",
|
"argon2-browser": "1.15.2",
|
||||||
"autoprefixer": "^10.0.4",
|
"autoprefixer": "^10.0.4",
|
||||||
|
|
Loading…
Reference in New Issue