mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2024-11-14 22:01:55 +08:00
feat(hotkey): add new macro input-text
This commit is contained in:
parent
d07ef6f642
commit
ed9a95ee71
@ -68,10 +68,10 @@ onMounted(async () => {
|
|||||||
deviceWaitForMetadataTask?.(payload.deviceName);
|
deviceWaitForMetadataTask?.(payload.deviceName);
|
||||||
break;
|
break;
|
||||||
case "ClipboardChanged":
|
case "ClipboardChanged":
|
||||||
console.log("剪切板变动", payload.clipboard);
|
console.log("ClipboardChanged", payload.clipboard);
|
||||||
break;
|
break;
|
||||||
case "ClipboardSetAck":
|
case "ClipboardSetAck":
|
||||||
console.log("剪切板设置成功", payload.sequence);
|
console.log("ClipboardSetAck", payload.sequence);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unknown reply", payload);
|
console.log("Unknown reply", payload);
|
||||||
|
@ -1,33 +1,41 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { h, onActivated, onMounted } from "vue";
|
import { h, nextTick, onActivated, onMounted, ref } from "vue";
|
||||||
import { NDialog, useDialog, useMessage } from "naive-ui";
|
import { NDialog, NInput, useDialog, useMessage } from "naive-ui";
|
||||||
import { useGlobalStore } from "../store/global";
|
import { useGlobalStore } from "../store/global";
|
||||||
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
||||||
import {
|
import {
|
||||||
applyShortcuts,
|
applyShortcuts,
|
||||||
clearShortcuts,
|
clearShortcuts,
|
||||||
listenToKeyEvent,
|
listenToEvent,
|
||||||
unlistenToKeyEvent,
|
unlistenToEvent,
|
||||||
updateScreenSizeAndMaskArea,
|
updateScreenSizeAndMaskArea,
|
||||||
} from "../hotkey";
|
} from "../hotkey";
|
||||||
import { KeySteeringWheel } from "../keyMappingConfig";
|
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 { getCurrent } from "@tauri-apps/api/webview";
|
||||||
|
import { PhysicalSize } from "@tauri-apps/api/dpi";
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
|
|
||||||
|
const showInputBoxRef = ref(false);
|
||||||
|
const inputBoxVal = ref("");
|
||||||
|
const inputInstRef = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
onBeforeRouteLeave(() => {
|
onBeforeRouteLeave(() => {
|
||||||
if (store.controledDevice) {
|
if (store.controledDevice) {
|
||||||
unlistenToKeyEvent();
|
unlistenToEvent();
|
||||||
clearShortcuts();
|
clearShortcuts();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onActivated(async () => {
|
onActivated(async () => {
|
||||||
|
cleanAfterimage();
|
||||||
const maskElement = document.getElementById("maskElement") as HTMLElement;
|
const maskElement = document.getElementById("maskElement") as HTMLElement;
|
||||||
|
|
||||||
if (store.controledDevice) {
|
if (store.controledDevice) {
|
||||||
@ -42,7 +50,7 @@ onActivated(async () => {
|
|||||||
store.keyMappingConfigList[store.curKeyMappingIndex]
|
store.keyMappingConfigList[store.curKeyMappingIndex]
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
listenToKeyEvent();
|
listenToEvent();
|
||||||
} else {
|
} else {
|
||||||
message.error("按键方案异常,请删除此方案");
|
message.error("按键方案异常,请删除此方案");
|
||||||
}
|
}
|
||||||
@ -52,8 +60,53 @@ onActivated(async () => {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
store.checkUpdate = checkUpdate;
|
store.checkUpdate = checkUpdate;
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
|
store.showInputBox = showInputBox;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInputKeyUp(event: KeyboardEvent) {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
pasteText();
|
||||||
|
} else if (event.key === "Escape") {
|
||||||
|
showInputBox(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInputBox(flag: boolean) {
|
||||||
|
if (flag) {
|
||||||
|
unlistenToEvent();
|
||||||
|
inputBoxVal.value = "";
|
||||||
|
showInputBoxRef.value = true;
|
||||||
|
document.addEventListener("keyup", handleInputKeyUp);
|
||||||
|
nextTick(() => {
|
||||||
|
inputInstRef.value?.focus();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.removeEventListener("keyup", handleInputKeyUp);
|
||||||
|
showInputBoxRef.value = false;
|
||||||
|
listenToEvent();
|
||||||
|
nextTick(() => {
|
||||||
|
cleanAfterimage();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pasteText() {
|
||||||
|
showInputBox(false);
|
||||||
|
if (!inputBoxVal.value) return;
|
||||||
|
sendSetClipboard({
|
||||||
|
sequence: new Date().getTime() % 100000,
|
||||||
|
text: inputBoxVal.value,
|
||||||
|
paste: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function toStartServer() {
|
function toStartServer() {
|
||||||
router.replace({ name: "device" });
|
router.replace({ name: "device" });
|
||||||
}
|
}
|
||||||
@ -114,6 +167,14 @@ async function checkUpdate() {
|
|||||||
</div>
|
</div>
|
||||||
<template v-if="store.keyMappingConfigList.length">
|
<template v-if="store.keyMappingConfigList.length">
|
||||||
<div @contextmenu.prevent class="mask" id="maskElement"></div>
|
<div @contextmenu.prevent class="mask" id="maskElement"></div>
|
||||||
|
<div v-show="showInputBoxRef" class="input-box">
|
||||||
|
<NInput
|
||||||
|
ref="inputInstRef"
|
||||||
|
v-model:value="inputBoxVal"
|
||||||
|
type="text"
|
||||||
|
placeholder="Input text and then press enter/esc"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="store.maskButton.show"
|
v-if="store.maskButton.show"
|
||||||
:style="'--transparency: ' + store.maskButton.transparency"
|
:style="'--transparency: ' + store.maskButton.transparency"
|
||||||
@ -174,6 +235,26 @@ async function checkUpdate() {
|
|||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input-box {
|
||||||
|
z-index: 4;
|
||||||
|
position: absolute;
|
||||||
|
left: 70px;
|
||||||
|
top: 30px;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
|
||||||
|
.n-input {
|
||||||
|
width: 50%;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 15%;
|
||||||
|
margin: auto;
|
||||||
|
background-color: var(--content-bg-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.button-layer {
|
.button-layer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 70px;
|
left: 70px;
|
||||||
@ -220,7 +301,6 @@ async function checkUpdate() {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 1;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 70px;
|
left: 70px;
|
||||||
top: 30px;
|
top: 30px;
|
||||||
|
@ -73,10 +73,10 @@ function onAddButtonSelect(
|
|||||||
(keyMapping as KeyTap).time = 80;
|
(keyMapping as KeyTap).time = 80;
|
||||||
} else if (type === "SteeringWheel") {
|
} else if (type === "SteeringWheel") {
|
||||||
(keyMapping as unknown as KeyMappingSteeringWheel).key = {
|
(keyMapping as unknown as KeyMappingSteeringWheel).key = {
|
||||||
left: "NONE",
|
left: "NONE1",
|
||||||
right: "NONE",
|
right: "NONE2",
|
||||||
up: "NONE",
|
up: "NONE3",
|
||||||
down: "NONE",
|
down: "NONE4",
|
||||||
};
|
};
|
||||||
(keyMapping as unknown as KeyMappingSteeringWheel).offset = 100;
|
(keyMapping as unknown as KeyMappingSteeringWheel).offset = 100;
|
||||||
} else if (type === "DirectionalSkill") {
|
} else if (type === "DirectionalSkill") {
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
KeyTriggerWhenDoublePressedSkill,
|
KeyTriggerWhenDoublePressedSkill,
|
||||||
KeyTriggerWhenPressedSkill,
|
KeyTriggerWhenPressedSkill,
|
||||||
} from "./keyMappingConfig";
|
} from "./keyMappingConfig";
|
||||||
|
import { useGlobalStore } from "./store/global";
|
||||||
|
|
||||||
function clientxToPosx(clientx: number) {
|
function clientxToPosx(clientx: number) {
|
||||||
return clientx < 70
|
return clientx < 70
|
||||||
@ -948,6 +949,12 @@ function addShortcut(
|
|||||||
* 1000,
|
* 1000,
|
||||||
* ],
|
* ],
|
||||||
* },
|
* },
|
||||||
|
* // input-text
|
||||||
|
* {
|
||||||
|
* type: "input-text",
|
||||||
|
* // 1:on, 2:off
|
||||||
|
* args: [1]
|
||||||
|
* }
|
||||||
* ]);
|
* ]);
|
||||||
*/
|
*/
|
||||||
async function execMacro(
|
async function execMacro(
|
||||||
@ -1025,6 +1032,15 @@ async function execMacro(
|
|||||||
intervalBetweenPos: cmd.args[3],
|
intervalBetweenPos: cmd.args[3],
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "input-text":
|
||||||
|
if (cmd.args[0] === 1) {
|
||||||
|
// on
|
||||||
|
useGlobalStore().showInputBox(true);
|
||||||
|
} else {
|
||||||
|
// off
|
||||||
|
useGlobalStore().showInputBox(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.error("Invalid command: ", cmd);
|
console.error("Invalid command: ", cmd);
|
||||||
return;
|
return;
|
||||||
@ -1175,25 +1191,29 @@ function applyKeyMappingConfigShortcuts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listenToKeyEvent() {
|
export function listenToEvent() {
|
||||||
window.addEventListener("keydown", keydownHandler);
|
window.addEventListener("keydown", keydownHandler);
|
||||||
window.addEventListener("keyup", keyupHandler);
|
window.addEventListener("keyup", keyupHandler);
|
||||||
|
window.addEventListener("mousedown", handleMouseDown);
|
||||||
|
window.addEventListener("mousemove", handleMouseMove);
|
||||||
|
window.addEventListener("mouseup", handleMouseUp);
|
||||||
|
window.addEventListener("wheel", handleMouseWheel);
|
||||||
loopFlag = true;
|
loopFlag = true;
|
||||||
execLoopCB();
|
execLoopCB();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unlistenToKeyEvent() {
|
export function unlistenToEvent() {
|
||||||
window.removeEventListener("keydown", keydownHandler);
|
window.removeEventListener("keydown", keydownHandler);
|
||||||
window.removeEventListener("keyup", keyupHandler);
|
window.removeEventListener("keyup", keyupHandler);
|
||||||
loopFlag = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearShortcuts() {
|
|
||||||
window.removeEventListener("mousedown", handleMouseDown);
|
window.removeEventListener("mousedown", handleMouseDown);
|
||||||
window.removeEventListener("mousemove", handleMouseMove);
|
window.removeEventListener("mousemove", handleMouseMove);
|
||||||
window.removeEventListener("mouseup", handleMouseUp);
|
window.removeEventListener("mouseup", handleMouseUp);
|
||||||
window.removeEventListener("wheel", handleMouseWheel);
|
window.removeEventListener("wheel", handleMouseWheel);
|
||||||
|
|
||||||
|
loopFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearShortcuts() {
|
||||||
downKeyMap.clear();
|
downKeyMap.clear();
|
||||||
downKeyCBMap.clear();
|
downKeyCBMap.clear();
|
||||||
loopDownKeyCBMap.clear();
|
loopDownKeyCBMap.clear();
|
||||||
@ -1216,11 +1236,6 @@ export function applyShortcuts(
|
|||||||
keyMappingConfig: KeyMappingConfig
|
keyMappingConfig: KeyMappingConfig
|
||||||
) {
|
) {
|
||||||
maskElement = element;
|
maskElement = element;
|
||||||
window.addEventListener("mousedown", handleMouseDown);
|
|
||||||
window.addEventListener("mousemove", handleMouseMove);
|
|
||||||
window.addEventListener("mouseup", handleMouseUp);
|
|
||||||
window.addEventListener("wheel", handleMouseWheel);
|
|
||||||
|
|
||||||
addClickShortcuts("M0", 0);
|
addClickShortcuts("M0", 0);
|
||||||
return applyKeyMappingConfigShortcuts(keyMappingConfig);
|
return applyKeyMappingConfigShortcuts(keyMappingConfig);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ interface KeyTap extends Key {
|
|||||||
time: number;
|
time: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyMacroType = "touch" | "sleep" | "swipe";
|
type KeyMacroType = "touch" | "sleep" | "swipe" | "input-text";
|
||||||
type KeyMacroArgs = any[];
|
type KeyMacroArgs = any[];
|
||||||
|
|
||||||
type KeyMacroList = Array<{
|
type KeyMacroList = Array<{
|
||||||
|
@ -39,6 +39,8 @@ export const useGlobalStore = defineStore("global", () => {
|
|||||||
show: true,
|
show: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const showInputBox: (_: boolean) => void = (_: boolean) => {};
|
||||||
|
|
||||||
let checkUpdate: () => Promise<void> = async () => {};
|
let checkUpdate: () => Promise<void> = async () => {};
|
||||||
|
|
||||||
function applyEditKeyMappingList(): boolean {
|
function applyEditKeyMappingList(): boolean {
|
||||||
@ -90,6 +92,7 @@ export const useGlobalStore = defineStore("global", () => {
|
|||||||
curKeyMappingIndex,
|
curKeyMappingIndex,
|
||||||
editKeyMappingList,
|
editKeyMappingList,
|
||||||
maskButton,
|
maskButton,
|
||||||
|
showInputBox,
|
||||||
applyEditKeyMappingList,
|
applyEditKeyMappingList,
|
||||||
resetEditKeyMappingList,
|
resetEditKeyMappingList,
|
||||||
setKeyMappingIndex,
|
setKeyMappingIndex,
|
||||||
|
Loading…
Reference in New Issue
Block a user