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] Visually setting the mapping
- [x] Key mapping config import and export - [x] Key mapping config import and export
- [x] Update check - [x] Update check
- [x] Switch between key mapping and input-text box
- [ ] Internationalization (i18n) - [ ] Internationalization (i18n)
- [ ] Switch between key mapping and raw input
- [ ] Gamepad key mapping - [ ] Gamepad key mapping
- [ ] Better macro support - [ ] Better macro support
- [ ] Provide external interface through websocket - [ ] Provide external interface through websocket

View File

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