native auto type: unpressing keys

pull/1705/head
antelle 2021-01-30 20:22:13 +01:00
parent 1fa0eebc3b
commit cd2de3a1db
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
9 changed files with 50 additions and 27 deletions

View File

@ -69,6 +69,10 @@ class AutoTypeEmitter {
this.mod = {};
}
begin() {
this.withCallback(NativeModules.kbdEnsureModifierNotPressed());
}
setMod(mod, enabled) {
// TODO: press the modifier
if (enabled) {
@ -79,17 +83,21 @@ class AutoTypeEmitter {
}
text(str) {
this.withCallback(NativeModules.kbdText(str));
if (!str) {
return this.withCallback(Promise.resolve());
}
const mod = Object.keys(this.mod);
if (mod.length) {
// TODO
} else {
this.withCallback(NativeModules.kbdText(str));
}
}
key(key) {
const mods = Object.keys(this.mod);
if (typeof key === 'number') {
this.withCallback(
NativeModules.kbdKeyMoveWithCharacter(true, 0, key, mods).then(() =>
NativeModules.kbdKeyMoveWithCharacter(false, 0, key, mods)
)
);
this.withCallback(NativeModules.kbdKeyPressWithCharacter(0, key, mods));
} else {
if (!KeyMap[key]) {
return this.callback('Bad key: ' + key);

View File

@ -445,7 +445,7 @@ AutoTypeRunner.prototype.run = function (callback, windowId) {
activeMod: {},
finished: null
};
this.emitNext();
this.emitter.begin();
};
AutoTypeRunner.prototype.emitNext = function (err) {

View File

@ -65,6 +65,10 @@ const AutoTypeEmitter = function (callback) {
this.pendingScript = [];
};
AutoTypeEmitter.prototype.begin = function () {
this.callback();
};
AutoTypeEmitter.prototype.setMod = function (mod, enabled) {
if (enabled) {
this.mod[ModMap[mod]] = true;

View File

@ -68,6 +68,10 @@ const AutoTypeEmitter = function (callback, windowId) {
}
};
AutoTypeEmitter.prototype.begin = function () {
this.callback();
};
AutoTypeEmitter.prototype.setMod = function (mod, enabled) {
if (enabled) {
this.mod[ModMap[mod]] = true;

View File

@ -65,6 +65,10 @@ const AutoTypeEmitter = function (callback) {
this.pendingScript = [];
};
AutoTypeEmitter.prototype.begin = function () {
this.callback();
};
AutoTypeEmitter.prototype.setMod = function (mod, enabled) {
if (enabled) {
this.mod[ModMap[mod]] = true;

View File

@ -238,19 +238,19 @@ if (Launcher) {
return this.call('kbdShortcut', code, modifiers);
},
kbdKeyMoveWithCode(down, code, modifiers) {
return this.call('kbdKeyMoveWithCode', down, code, modifiers);
// kbdKeyMoveWithCode(down, code, modifiers) {
// return this.call('kbdKeyMoveWithCode', down, code, modifiers);
// },
//
// kbdKeyMoveWithModifier(down, modifiers) {
// return this.call('kbdKeyMoveWithModifier', down, modifiers);
// },
kbdKeyPressWithCharacter(character, code, modifiers) {
return this.call('kbdKeyPressWithCharacter', character, code, modifiers);
},
kbdKeyMoveWithModifier(down, modifiers) {
return this.call('kbdKeyMoveWithModifier', down, modifiers);
},
kbdKeyMoveWithCharacter(down, character, code, modifiers) {
return this.call('kbdKeyMoveWithCharacter', down, character, code, modifiers);
},
ensureModifierNotPressed() {
kbdEnsureModifierNotPressed() {
return this.call('kbdEnsureModifierNotPressed');
}
};

View File

@ -135,8 +135,10 @@ const messageHandlers = {
return getAutoType().keyMoveWithModifier(down, kbdModifier(modifiers));
},
kbdKeyMoveWithCharacter(down, character, code, modifiers) {
return getAutoType().keyMoveWithCharacter(down, character, code, kbdModifier(modifiers));
kbdKeyPressWithCharacter(down, character, code, modifiers) {
const typer = getAutoType();
typer.keyMoveWithCharacter(true, character, code, kbdModifier(modifiers));
typer.keyMoveWithCharacter(false, character, code, kbdModifier(modifiers));
},
kbdEnsureModifierNotPressed() {
@ -179,6 +181,7 @@ function getAutoType() {
if (!autoType) {
const keyboardAutoType = reqNative('keyboard-auto-type');
autoType = new keyboardAutoType.AutoType();
autoType.setCheckPressedModifiers(false);
}
return autoType;
}

10
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.5/keeweb-native-modules.tgz",
"integrity": "sha512-vj4bM0I2oA3A5FWnISM61Fbz8I3DSOX7+Qm0ekRzCNCzy/MxTgTqZeiCLWq7YmdEFuNAu70cI6RCSDgFKBZZJg=="
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.7/keeweb-native-modules.tgz",
"integrity": "sha512-rIe5RAFSIW6kHZ2dsf3w5M+7OJxgG6lKMrYxd2nbV+4VJvKK1+Fu14X3jBwoMlSEkqeuyF+GXb78isu6X0hxIQ=="
},
"@sindresorhus/is": {
"version": "0.14.0",
@ -5294,9 +5294,9 @@
}
},
"electron": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/electron/-/electron-11.0.3.tgz",
"integrity": "sha512-nNfbLi7Q1xfJXOEO2adck5TS6asY4Jxc332E4Te8XfQ9hcaC3GiCdeEqk9FndNCwxhJA5Lr9jfSGRTwWebFa/w==",
"version": "11.2.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-11.2.1.tgz",
"integrity": "sha512-Im1y29Bnil+Nzs+FCTq01J1OtLbs+2ZGLLllaqX/9n5GgpdtDmZhS/++JHBsYZ+4+0n7asO+JKQgJD+CqPClzg==",
"requires": {
"@electron/get": "^1.0.1",
"@types/node": "^12.0.12",

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.5/keeweb-native-modules.tgz",
"@keeweb/keeweb-native-modules": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.7.7/keeweb-native-modules.tgz",
"adm-zip": "^0.5.1",
"argon2-browser": "1.15.2",
"autoprefixer": "^10.0.4",
@ -31,7 +31,7 @@
"cross-env": "^7.0.2",
"css-loader": "^5.0.1",
"dompurify": "^2.2.6",
"electron": "^11.0.3",
"electron": "^11.2.1",
"electron-builder": "^22.9.1",
"electron-notarize": "^1.0.0",
"electron-osx-sign": "^0.5.0",