feat(Mask): send enter after paste text

This commit is contained in:
AkiChase 2024-05-07 10:58:42 +08:00
parent 0e2d0c3025
commit a20ce2cef8
2 changed files with 40 additions and 8 deletions

View File

@ -13,8 +13,8 @@ Due to the delay and blurred image quality of the mirror screen. This project fo
- [x] Visually setting the mapping
- [x] Key mapping config import and export
- [x] Update check
- [x] Switch between key mapping and input-text box
- [ ] Internationalization (i18n)
- [ ] Switch between key mapping and raw input
- [ ] Gamepad key mapping
- [ ] Better macro support
- [ ] Provide external interface through websocket

View File

@ -14,9 +14,16 @@ import { KeySteeringWheel } from "../keyMappingConfig";
import { getVersion } from "@tauri-apps/api/app";
import { fetch } from "@tauri-apps/plugin-http";
import { open } from "@tauri-apps/plugin-shell";
import { sendSetClipboard } from "../frontcommand/controlMsg";
import { getCurrent } from "@tauri-apps/api/webview";
import { PhysicalSize } from "@tauri-apps/api/dpi";
import {
sendInjectKeycode,
sendSetClipboard,
} from "../frontcommand/controlMsg";
import { getCurrent, PhysicalSize } from "@tauri-apps/api/window";
import {
AndroidKeyEventAction,
AndroidKeycode,
AndroidMetastate,
} from "../frontcommand/android";
const store = useGlobalStore();
const router = useRouter();
@ -65,9 +72,10 @@ onMounted(() => {
async function cleanAfterimage() {
const appWindow = getCurrent();
const oSize = await appWindow.size();
await appWindow.setSize(new PhysicalSize(oSize.width, oSize.height - 1));
await appWindow.setSize(oSize);
const oldSize = await appWindow.outerSize();
const newSize = new PhysicalSize(oldSize.width, oldSize.height + 1);
await appWindow.setSize(newSize);
await appWindow.setSize(oldSize);
}
function handleInputBoxClick(event: MouseEvent) {
@ -95,6 +103,7 @@ function showInputBox(flag: boolean) {
});
} else {
document.removeEventListener("keyup", handleInputKeyUp);
inputInstRef.value?.blur();
showInputBoxRef.value = false;
listenToEvent();
nextTick(() => {
@ -103,7 +112,15 @@ function showInputBox(flag: boolean) {
}
}
function pasteText() {
function sleep(time: number) {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, time);
});
}
async function pasteText() {
showInputBox(false);
if (!inputBoxVal.value) return;
sendSetClipboard({
@ -111,6 +128,21 @@ function pasteText() {
text: inputBoxVal.value,
paste: true,
});
await sleep(300);
// send enter
await sendInjectKeycode({
action: AndroidKeyEventAction.AKEY_EVENT_ACTION_DOWN,
keycode: AndroidKeycode.AKEYCODE_ENTER,
repeat: 0,
metastate: AndroidMetastate.AMETA_NONE,
});
await sleep(50);
await sendInjectKeycode({
action: AndroidKeyEventAction.AKEY_EVENT_ACTION_UP,
keycode: AndroidKeycode.AKEYCODE_ENTER,
repeat: 0,
metastate: AndroidMetastate.AMETA_NONE,
});
}
function toStartServer() {