feat(hotkey): change input-box to key-input-mode

This commit is contained in:
AkiChase 2024-05-22 17:11:30 +08:00
parent 68a7746b1e
commit 006b1c42ad
10 changed files with 437 additions and 134 deletions

View File

@ -88,7 +88,6 @@ pub struct Adb;
impl Adb {
pub fn cmd_base() -> Command {
let adb_path = share::ADB_PATH.lock().unwrap().clone();
println!("{}", &adb_path);
#[cfg(target_os = "windows")]
{
let mut cmd = Command::new(adb_path);

View File

@ -284,7 +284,8 @@ async function deviceGetScreenSize() {
const size = await getDeviceScreenSize(id);
store.hideLoading();
message.success(
t("pages.Device.deviceGetScreenSize") + `${size[0]} x ${size[1]}`
t("pages.Device.deviceGetScreenSize") + `${size[0]} x ${size[1]}`,
{ keepAliveOnHover: true }
);
}

View File

@ -1,15 +1,10 @@
<script setup lang="ts">
import { h, nextTick, onActivated, onMounted, ref } from "vue";
import {
MessageReactive,
NDialog,
NInput,
useDialog,
useMessage,
} from "naive-ui";
import { h, onActivated, onMounted } from "vue";
import { MessageReactive, NDialog, useDialog, useMessage } from "naive-ui";
import { useGlobalStore } from "../store/global";
import { onBeforeRouteLeave, useRouter } from "vue-router";
import {
KeyInputHandler,
applyShortcuts,
clearShortcuts,
listenToEvent,
@ -19,12 +14,9 @@ import { KeyMappingConfig, 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, PhysicalSize } from "@tauri-apps/api/window";
import { AndroidKeycode } from "../frontcommand/android";
import { Store } from "@tauri-apps/plugin-store";
import { useI18n } from "vue-i18n";
import { SendKeyAction, sendKey } from "../frontcommand/scrcpyMaskCmd";
import { checkAdbAvailable } from "../invoke";
const { t } = useI18n();
@ -33,14 +25,11 @@ const router = useRouter();
const message = useMessage();
const dialog = useDialog();
const showInputBoxRef = ref(false);
const inputBoxVal = ref("");
const inputInstRef = ref<HTMLInputElement | null>(null);
onBeforeRouteLeave(() => {
if (store.controledDevice) {
unlistenToEvent();
clearShortcuts();
if (store.keyInputFlag) KeyInputHandler.removeEventListener();
}
});
@ -68,7 +57,6 @@ onActivated(async () => {
onMounted(async () => {
await loadLocalStore();
store.checkUpdate = checkUpdate;
store.showInputBox = showInputBox;
if (store.checkUpdateAtStart) checkUpdate();
store.checkAdb = checkAdb;
setTimeout(() => {
@ -159,64 +147,6 @@ async function cleanAfterimage() {
await appWindow.setSize(oldSize);
}
function handleInputBoxClick(event: MouseEvent) {
if (event.target === document.getElementById("input-box")) {
showInputBox(false);
}
}
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);
inputInstRef.value?.blur();
showInputBoxRef.value = false;
listenToEvent();
nextTick(() => {
cleanAfterimage();
});
}
}
function sleep(time: number) {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, time);
});
}
async function pasteText() {
showInputBox(false);
if (!inputBoxVal.value) return;
sendSetClipboard({
sequence: new Date().getTime() % 100000,
text: inputBoxVal.value,
paste: true,
});
await sleep(300);
// send enter
await sendKey({
action: SendKeyAction.Default,
keycode: AndroidKeycode.AKEYCODE_ENTER,
});
}
function toStartServer() {
router.replace({ name: "device" });
}
@ -296,19 +226,6 @@ async function checkUpdate() {
</div>
<template v-if="store.keyMappingConfigList.length">
<div @contextmenu.prevent class="mask" id="maskElement"></div>
<div
v-show="showInputBoxRef"
class="input-box"
id="input-box"
@click="handleInputBoxClick"
>
<NInput
ref="inputInstRef"
v-model:value="inputBoxVal"
type="text"
:placeholder="$t('pages.Mask.inputBoxPlaceholder')"
/>
</div>
<div
v-if="store.maskButton.show"
:style="'--transparency: ' + store.maskButton.transparency"
@ -369,26 +286,6 @@ async function checkUpdate() {
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 {
position: absolute;
left: 70px;

View File

@ -0,0 +1,118 @@
import { UIEventsCode } from "./UIEventsCode";
import { AndroidKeycode } from "./android";
export const KeyToCodeMap = new Map([
[UIEventsCode.Backquote, AndroidKeycode.AKEYCODE_GRAVE],
[UIEventsCode.Backslash, AndroidKeycode.AKEYCODE_BACKSLASH],
[UIEventsCode.BracketLeft, AndroidKeycode.AKEYCODE_LEFT_BRACKET],
[UIEventsCode.BracketRight, AndroidKeycode.AKEYCODE_RIGHT_BRACKET],
[UIEventsCode.Comma, AndroidKeycode.AKEYCODE_COMMA],
[UIEventsCode.Digit0, AndroidKeycode.AKEYCODE_0],
[UIEventsCode.Digit1, AndroidKeycode.AKEYCODE_1],
[UIEventsCode.Digit2, AndroidKeycode.AKEYCODE_2],
[UIEventsCode.Digit3, AndroidKeycode.AKEYCODE_3],
[UIEventsCode.Digit4, AndroidKeycode.AKEYCODE_4],
[UIEventsCode.Digit5, AndroidKeycode.AKEYCODE_5],
[UIEventsCode.Digit6, AndroidKeycode.AKEYCODE_6],
[UIEventsCode.Digit7, AndroidKeycode.AKEYCODE_7],
[UIEventsCode.Digit8, AndroidKeycode.AKEYCODE_8],
[UIEventsCode.Digit9, AndroidKeycode.AKEYCODE_9],
[UIEventsCode.Equal, AndroidKeycode.AKEYCODE_EQUALS],
[UIEventsCode.IntlRo, AndroidKeycode.AKEYCODE_RO],
[UIEventsCode.IntlYen, AndroidKeycode.AKEYCODE_YEN],
[UIEventsCode.KeyA, AndroidKeycode.AKEYCODE_A],
[UIEventsCode.KeyB, AndroidKeycode.AKEYCODE_B],
[UIEventsCode.KeyC, AndroidKeycode.AKEYCODE_C],
[UIEventsCode.KeyD, AndroidKeycode.AKEYCODE_D],
[UIEventsCode.KeyE, AndroidKeycode.AKEYCODE_E],
[UIEventsCode.KeyF, AndroidKeycode.AKEYCODE_F],
[UIEventsCode.KeyG, AndroidKeycode.AKEYCODE_G],
[UIEventsCode.KeyH, AndroidKeycode.AKEYCODE_H],
[UIEventsCode.KeyI, AndroidKeycode.AKEYCODE_I],
[UIEventsCode.KeyJ, AndroidKeycode.AKEYCODE_J],
[UIEventsCode.KeyK, AndroidKeycode.AKEYCODE_K],
[UIEventsCode.KeyL, AndroidKeycode.AKEYCODE_L],
[UIEventsCode.KeyM, AndroidKeycode.AKEYCODE_M],
[UIEventsCode.KeyN, AndroidKeycode.AKEYCODE_N],
[UIEventsCode.KeyO, AndroidKeycode.AKEYCODE_O],
[UIEventsCode.KeyP, AndroidKeycode.AKEYCODE_P],
[UIEventsCode.KeyQ, AndroidKeycode.AKEYCODE_Q],
[UIEventsCode.KeyR, AndroidKeycode.AKEYCODE_R],
[UIEventsCode.KeyS, AndroidKeycode.AKEYCODE_S],
[UIEventsCode.KeyT, AndroidKeycode.AKEYCODE_T],
[UIEventsCode.KeyU, AndroidKeycode.AKEYCODE_U],
[UIEventsCode.KeyV, AndroidKeycode.AKEYCODE_V],
[UIEventsCode.KeyW, AndroidKeycode.AKEYCODE_W],
[UIEventsCode.KeyX, AndroidKeycode.AKEYCODE_X],
[UIEventsCode.KeyY, AndroidKeycode.AKEYCODE_Y],
[UIEventsCode.KeyZ, AndroidKeycode.AKEYCODE_Z],
[UIEventsCode.Minus, AndroidKeycode.AKEYCODE_MINUS],
[UIEventsCode.Period, AndroidKeycode.AKEYCODE_PERIOD],
[UIEventsCode.Quote, AndroidKeycode.AKEYCODE_APOSTROPHE],
[UIEventsCode.Semicolon, AndroidKeycode.AKEYCODE_SEMICOLON],
[UIEventsCode.Slash, AndroidKeycode.AKEYCODE_SLASH],
[UIEventsCode.KanaMode, AndroidKeycode.AKEYCODE_KANA],
[UIEventsCode.Delete, AndroidKeycode.AKEYCODE_FORWARD_DEL],
[UIEventsCode.End, AndroidKeycode.AKEYCODE_MOVE_END],
[UIEventsCode.Help, AndroidKeycode.AKEYCODE_HELP],
[UIEventsCode.Home, AndroidKeycode.AKEYCODE_MOVE_HOME],
[UIEventsCode.Insert, AndroidKeycode.AKEYCODE_INSERT],
[UIEventsCode.PageDown, AndroidKeycode.AKEYCODE_PAGE_DOWN],
[UIEventsCode.PageUp, AndroidKeycode.AKEYCODE_PAGE_UP],
[UIEventsCode.AltLeft, AndroidKeycode.AKEYCODE_ALT_LEFT],
[UIEventsCode.AltRight, AndroidKeycode.AKEYCODE_ALT_RIGHT],
[UIEventsCode.Backspace, AndroidKeycode.AKEYCODE_DEL],
[UIEventsCode.CapsLock, AndroidKeycode.AKEYCODE_CAPS_LOCK],
[UIEventsCode.ControlLeft, AndroidKeycode.AKEYCODE_CTRL_LEFT],
[UIEventsCode.ControlRight, AndroidKeycode.AKEYCODE_CTRL_RIGHT],
[UIEventsCode.Enter, AndroidKeycode.AKEYCODE_ENTER],
[UIEventsCode.MetaLeft, AndroidKeycode.AKEYCODE_META_LEFT],
[UIEventsCode.MetaRight, AndroidKeycode.AKEYCODE_META_RIGHT],
[UIEventsCode.ShiftLeft, AndroidKeycode.AKEYCODE_SHIFT_LEFT],
[UIEventsCode.ShiftRight, AndroidKeycode.AKEYCODE_SHIFT_RIGHT],
[UIEventsCode.Space, AndroidKeycode.AKEYCODE_SPACE],
[UIEventsCode.Tab, AndroidKeycode.AKEYCODE_TAB],
[UIEventsCode.ArrowLeft, AndroidKeycode.AKEYCODE_DPAD_LEFT],
[UIEventsCode.ArrowUp, AndroidKeycode.AKEYCODE_DPAD_UP],
[UIEventsCode.ArrowRight, AndroidKeycode.AKEYCODE_DPAD_RIGHT],
[UIEventsCode.ArrowDown, AndroidKeycode.AKEYCODE_DPAD_DOWN],
[UIEventsCode.NumLock, AndroidKeycode.AKEYCODE_NUM_LOCK],
[UIEventsCode.Numpad0, AndroidKeycode.AKEYCODE_NUMPAD_0],
[UIEventsCode.Numpad1, AndroidKeycode.AKEYCODE_NUMPAD_1],
[UIEventsCode.Numpad2, AndroidKeycode.AKEYCODE_NUMPAD_2],
[UIEventsCode.Numpad3, AndroidKeycode.AKEYCODE_NUMPAD_3],
[UIEventsCode.Numpad4, AndroidKeycode.AKEYCODE_NUMPAD_4],
[UIEventsCode.Numpad5, AndroidKeycode.AKEYCODE_NUMPAD_5],
[UIEventsCode.Numpad6, AndroidKeycode.AKEYCODE_NUMPAD_6],
[UIEventsCode.Numpad7, AndroidKeycode.AKEYCODE_NUMPAD_7],
[UIEventsCode.Numpad8, AndroidKeycode.AKEYCODE_NUMPAD_8],
[UIEventsCode.Numpad9, AndroidKeycode.AKEYCODE_NUMPAD_9],
[UIEventsCode.NumpadAdd, AndroidKeycode.AKEYCODE_NUMPAD_ADD],
[UIEventsCode.NumpadComma, AndroidKeycode.AKEYCODE_NUMPAD_COMMA],
[UIEventsCode.NumpadDecimal, AndroidKeycode.AKEYCODE_NUMPAD_DOT],
[UIEventsCode.NumpadDivide, AndroidKeycode.AKEYCODE_NUMPAD_DIVIDE],
[UIEventsCode.NumpadEnter, AndroidKeycode.AKEYCODE_NUMPAD_ENTER],
[UIEventsCode.NumpadEqual, AndroidKeycode.AKEYCODE_NUMPAD_EQUALS],
[UIEventsCode.NumpadMultiply, AndroidKeycode.AKEYCODE_NUMPAD_MULTIPLY],
[UIEventsCode.NumpadParenLeft, AndroidKeycode.AKEYCODE_NUMPAD_LEFT_PAREN],
[UIEventsCode.NumpadParenRight, AndroidKeycode.AKEYCODE_NUMPAD_RIGHT_PAREN],
[UIEventsCode.NumpadSubtract, AndroidKeycode.AKEYCODE_NUMPAD_SUBTRACT],
[UIEventsCode.Escape, AndroidKeycode.AKEYCODE_ESCAPE],
[UIEventsCode.F1, AndroidKeycode.AKEYCODE_F1],
[UIEventsCode.F2, AndroidKeycode.AKEYCODE_F2],
[UIEventsCode.F3, AndroidKeycode.AKEYCODE_F3],
[UIEventsCode.F4, AndroidKeycode.AKEYCODE_F4],
[UIEventsCode.F5, AndroidKeycode.AKEYCODE_F5],
[UIEventsCode.F6, AndroidKeycode.AKEYCODE_F6],
[UIEventsCode.F7, AndroidKeycode.AKEYCODE_F7],
[UIEventsCode.F8, AndroidKeycode.AKEYCODE_F8],
[UIEventsCode.F9, AndroidKeycode.AKEYCODE_F9],
[UIEventsCode.F10, AndroidKeycode.AKEYCODE_F10],
[UIEventsCode.F11, AndroidKeycode.AKEYCODE_F11],
[UIEventsCode.F12, AndroidKeycode.AKEYCODE_F12],
[UIEventsCode.Fn, AndroidKeycode.AKEYCODE_FUNCTION],
[UIEventsCode.PrintScreen, AndroidKeycode.AKEYCODE_SYSRQ],
[UIEventsCode.Pause, AndroidKeycode.AKEYCODE_BREAK],
]);

View File

@ -0,0 +1,191 @@
// https://w3c.github.io/uievents-code/
export enum UIEventsCode {
// 3.1.1.1. Writing System Keys
Backquote = "Backquote",
Backslash = "Backslash",
BracketLeft = "BracketLeft",
BracketRight = "BracketRight",
Comma = "Comma",
Digit0 = "Digit0",
Digit1 = "Digit1",
Digit2 = "Digit2",
Digit3 = "Digit3",
Digit4 = "Digit4",
Digit5 = "Digit5",
Digit6 = "Digit6",
Digit7 = "Digit7",
Digit8 = "Digit8",
Digit9 = "Digit9",
Equal = "Equal",
IntlBackslash = "IntlBackslash",
IntlRo = "IntlRo",
IntlYen = "IntlYen",
KeyA = "KeyA",
KeyB = "KeyB",
KeyC = "KeyC",
KeyD = "KeyD",
KeyE = "KeyE",
KeyF = "KeyF",
KeyG = "KeyG",
KeyH = "KeyH",
KeyI = "KeyI",
KeyJ = "KeyJ",
KeyK = "KeyK",
KeyL = "KeyL",
KeyM = "KeyM",
KeyN = "KeyN",
KeyO = "KeyO",
KeyP = "KeyP",
KeyQ = "KeyQ",
KeyR = "KeyR",
KeyS = "KeyS",
KeyT = "KeyT",
KeyU = "KeyU",
KeyV = "KeyV",
KeyW = "KeyW",
KeyX = "KeyX",
KeyY = "KeyY",
KeyZ = "KeyZ",
Minus = "Minus",
Period = "Period",
Quote = "Quote",
Semicolon = "Semicolon",
Slash = "Slash",
// 3.1.1.2. Functional Keys
AltLeft = "AltLeft",
AltRight = "AltRight",
Backspace = "Backspace",
CapsLock = "CapsLock",
ContextMenu = "ContextMenu",
ControlLeft = "ControlLeft",
ControlRight = "ControlRight",
Enter = "Enter",
MetaLeft = "MetaLeft",
MetaRight = "MetaRight",
ShiftLeft = "ShiftLeft",
ShiftRight = "ShiftRight",
Space = "Space",
Tab = "Tab",
Convert = "Convert",
KanaMode = "KanaMode",
Lang1 = "Lang1",
Lang2 = "Lang2",
Lang3 = "Lang3",
Lang4 = "Lang4",
Lang5 = "Lang5",
NonConvert = "NonConvert",
// 3.1.2. Control Pad Section
Delete = "Delete",
End = "End",
Help = "Help",
Home = "Home",
Insert = "Insert",
PageDown = "PageDown",
PageUp = "PageUp",
// 3.1.3. Arrow Pad Section
ArrowDown = "ArrowDown",
ArrowLeft = "ArrowLeft",
ArrowRight = "ArrowRight",
ArrowUp = "ArrowUp",
// 3.1.4. Numpad Section
NumLock = "NumLock",
Numpad0 = "Numpad0",
Numpad1 = "Numpad1",
Numpad2 = "Numpad2",
Numpad3 = "Numpad3",
Numpad4 = "Numpad4",
Numpad5 = "Numpad5",
Numpad6 = "Numpad6",
Numpad7 = "Numpad7",
Numpad8 = "Numpad8",
Numpad9 = "Numpad9",
NumpadAdd = "NumpadAdd",
NumpadBackspace = "NumpadBackspace",
NumpadClear = "NumpadClear",
NumpadClearEntry = "NumpadClearEntry",
NumpadComma = "NumpadComma",
NumpadDecimal = "NumpadDecimal",
NumpadDivide = "NumpadDivide",
NumpadEnter = "NumpadEnter",
NumpadEqual = "NumpadEqual",
NumpadHash = "NumpadHash",
NumpadMemoryAdd = "NumpadMemoryAdd",
NumpadMemoryClear = "NumpadMemoryClear",
NumpadMemoryRecall = "NumpadMemoryRecall",
NumpadMemoryStore = "NumpadMemoryStore",
NumpadMemorySubtract = "NumpadMemorySubtract",
NumpadMultiply = "NumpadMultiply",
NumpadParenLeft = "NumpadParenLeft",
NumpadParenRight = "NumpadParenRight",
NumpadStar = "NumpadStar",
NumpadSubtract = "NumpadSubtract",
// 3.1.5. Function Section
Escape = "Escape",
F1 = "F1",
F2 = "F2",
F3 = "F3",
F4 = "F4",
F5 = "F5",
F6 = "F6",
F7 = "F7",
F8 = "F8",
F9 = "F9",
F10 = "F10",
F11 = "F11",
F12 = "F12",
Fn = "Fn",
FnLock = "FnLock",
PrintScreen = "PrintScreen",
ScrollLock = "ScrollLock",
Pause = "Pause",
// 3.1.6. Media Keys
BrowserBack = "BrowserBack",
BrowserFavorites = "BrowserFavorites",
BrowserForward = "BrowserForward",
BrowserHome = "BrowserHome",
BrowserRefresh = "BrowserRefresh",
BrowserSearch = "BrowserSearch",
BrowserStop = "BrowserStop",
Eject = "Eject",
LaunchApp1 = "LaunchApp1",
LaunchApp2 = "LaunchApp2",
LaunchMail = "LaunchMail",
MediaPlayPause = "MediaPlayPause",
MediaSelect = "MediaSelect",
MediaStop = "MediaStop",
MediaTrackNext = "MediaTrackNext",
MediaTrackPrevious = "MediaTrackPrevious",
Power = "Power",
Sleep = "Sleep",
AudioVolumeDown = "AudioVolumeDown",
AudioVolumeMute = "AudioVolumeMute",
AudioVolumeUp = "AudioVolumeUp",
WakeUp = "WakeUp",
// 3.1.7. Legacy, Non-Standard and Special Keys
Hyper = "Hyper",
Super = "Super",
Turbo = "Turbo",
Abort = "Abort",
Resume = "Resume",
Suspend = "Suspend",
Again = "Again",
Copy = "Copy",
Cut = "Cut",
Find = "Find",
Open = "Open",
Paste = "Paste",
Props = "Props",
Select = "Select",
Undo = "Undo",
Hiragana = "Hiragana",
Katakana = "Katakana",
Unidentified = "Unidentified",
}

View File

@ -1,5 +1,5 @@
// https://github.com/jamiebuilds/tinykeys/pull/193/commits/2598ecb3db6b3948c7acbf0e7bd8b0674961ad61
import { useMessage } from "naive-ui";
import { MessageReactive, useMessage } from "naive-ui";
import {
SwipeAction,
TouchAction,
@ -25,6 +25,13 @@ import { useGlobalStore } from "./store/global";
import { LogicalPosition, getCurrent } from "@tauri-apps/api/window";
import { useI18n } from "vue-i18n";
import { UnlistenFn } from "@tauri-apps/api/event";
import { KeyToCodeMap } from "./frontcommand/KeyToCodeMap";
import {
AndroidKeyEventAction,
AndroidMetastate,
} from "./frontcommand/android";
import { UIEventsCode } from "./frontcommand/UIEventsCode";
import { sendInjectKeycode } from "./frontcommand/controlMsg";
function clientxToPosx(clientx: number) {
return clientx < 70
@ -646,6 +653,7 @@ function addClickShortcuts(key: string, pointerId: number) {
);
}
// add shortcut for sight mode
function addSightShortcuts(
relativeSize: { w: number; h: number },
sightKeyMapping: KeySight,
@ -989,6 +997,86 @@ function handleMouseWheel(event: WheelEvent) {
}
}
export class KeyInputHandler {
private static readonly repeatCounter: Map<number, number> = new Map();
private static msgReactive: MessageReactive | null = null;
private static handler(event: KeyboardEvent) {
const keycode = KeyToCodeMap.get(event.code as UIEventsCode);
if (!keycode) {
return;
}
let action: AndroidKeyEventAction;
let repeatCount = 0;
if (event.type === "keydown") {
action = AndroidKeyEventAction.AKEY_EVENT_ACTION_DOWN;
if (event.repeat) {
let count = KeyInputHandler.repeatCounter.get(keycode);
if (typeof count !== "number") {
count = 1;
} else {
count++;
}
repeatCount = count;
KeyInputHandler.repeatCounter.set(keycode, count);
}
} else if (event.type === "keyup") {
action = AndroidKeyEventAction.AKEY_EVENT_ACTION_UP;
KeyInputHandler.repeatCounter.delete(keycode);
} else {
return;
}
const metaState =
(event.getModifierState("Alt") ? AndroidMetastate.AMETA_ALT_ON : 0) |
(event.getModifierState("Shift") ? AndroidMetastate.AMETA_SHIFT_ON : 0) |
(event.getModifierState("Control") ? AndroidMetastate.AMETA_CTRL_ON : 0) |
(event.getModifierState("Meta") ? AndroidMetastate.AMETA_META_ON : 0) |
(event.getModifierState("CapsLock")
? AndroidMetastate.AMETA_CAPS_LOCK_ON
: 0) |
(event.getModifierState("ScrollLock")
? AndroidMetastate.AMETA_SCROLL_LOCK_ON
: 0) |
(event.getModifierState("NumLock")
? AndroidMetastate.AMETA_NUM_LOCK_ON
: 0);
// const controlMessage = new KeyCodeControlMessage(
// action,
// keyCode,
// repeatCount,
// metaState
// );
sendInjectKeycode({
action,
keycode,
repeat: repeatCount,
metastate: metaState,
});
event.preventDefault();
}
public static addEventListener() {
KeyInputHandler.msgReactive = message.info(t("pages.Mask.keyInputMode"), {
duration: 0,
closable: true,
onClose: () => {
KeyInputHandler.removeEventListener();
listenToEvent(true);
store.keyInputFlag = false;
},
});
window.addEventListener("keydown", KeyInputHandler.handler);
window.addEventListener("keyup", KeyInputHandler.handler);
}
public static removeEventListener() {
if (KeyInputHandler.msgReactive) {
KeyInputHandler.msgReactive.destroy();
KeyInputHandler.msgReactive = null;
}
window.removeEventListener("keydown", KeyInputHandler.handler);
window.removeEventListener("keyup", KeyInputHandler.handler);
}
}
function addShortcut(
key: string,
downCB?: () => Promise<void>,
@ -1047,23 +1135,23 @@ function addShortcut(
* {
* type: "touch",
* // op, pointerId, posX, posY
* args: ["down", 5, ["mouse", -10], 600],
* args: ["down", 5, ["mouse", -10], 600]
* },
* // sleep 1000ms
* {
* type: "sleep",
* // time(ms)
* args: [1000],
* args: [1000]
* },
* // touch up
* {
* type: "touch",
* args: ["up", 5, ["mouse", 10], 600],
* args: ["up", 5, ["mouse", 10], 600]
* },
* // touch 1000ms
* {
* type: "touch",
* args: ["default", 5, ["mouse", 10], 600, 1000],
* args: ["default", 5, ["mouse", 10], 600, 1000]
* },
* // swipe
* {
@ -1074,18 +1162,17 @@ function addShortcut(
* [
* [
* ["mouse", 100],
* ["mouse", -100],
* ["mouse", -100]
* ],
* ["mouse", "mouse"],
* ["mouse", "mouse"]
* ],
* 1000,
* ],
* 1000
* ]
* },
* // input-text
* // key-input-mode
* {
* type: "input-text",
* // 1:on, 2:off
* args: [1]
* type: "key-input-mode",
* args: []
* }
* ]);
*/
@ -1158,13 +1245,17 @@ async function execMacro(
intervalBetweenPos: cmd.args[3],
});
break;
case "input-text":
if (cmd.args[0] === 1) {
case "key-input-mode":
if (!store.keyInputFlag) {
// on
useGlobalStore().showInputBox(true);
unlistenToEvent(true);
KeyInputHandler.addEventListener();
store.keyInputFlag = true;
} else {
// off
useGlobalStore().showInputBox(false);
KeyInputHandler.removeEventListener();
listenToEvent(true);
store.keyInputFlag = false;
}
break;
default:
@ -1352,9 +1443,11 @@ async function touchX(
});
}
export function listenToEvent() {
export function listenToEvent(onlyKeyEvent = false) {
window.addEventListener("keydown", handleKeydown);
window.addEventListener("keyup", handleKeyup);
if (onlyKeyEvent) return;
window.addEventListener("mousedown", handleMouseDown);
window.addEventListener("mousemove", handleMouseMove);
window.addEventListener("mouseup", handleMouseUp);
@ -1363,9 +1456,11 @@ export function listenToEvent() {
execLoopCB();
}
export function unlistenToEvent() {
export function unlistenToEvent(onlyKeyEvent = false) {
window.removeEventListener("keydown", handleKeydown);
window.removeEventListener("keyup", handleKeyup);
if (onlyKeyEvent) return;
window.removeEventListener("mousedown", handleMouseDown);
window.removeEventListener("mousemove", handleMouseMove);
window.removeEventListener("mouseup", handleMouseUp);

View File

@ -58,7 +58,8 @@
"positiveText": "To control"
},
"sightMode": "Mouse is locked, press {0} to unlock",
"checkAdb": "adb is not available and the software cannot run normally. Please ensure that adb is installed on the system and added to the Path environment variable correctly: {0}"
"checkAdb": "adb is not available and the software cannot run normally. Please ensure that adb is installed on the system and added to the Path environment variable correctly: {0}",
"keyInputMode": "Has entered the keystroke input mode, close this message to exit."
},
"Setting": {
"tabs": {

View File

@ -58,7 +58,8 @@
},
"inputBoxPlaceholder": "输入文本后按Enter/Esc",
"sightMode": "鼠标已锁定, 按 {0} 键解锁",
"checkAdb": "adb不可用软件无法正常运行请确保系统已安装adb并正确添加到了Path环境变量中: {0}"
"checkAdb": "adb不可用软件无法正常运行请确保系统已安装adb并正确添加到了Path环境变量中: {0}",
"keyInputMode": "已进入按键输入模式,关闭本消息可退出"
},
"Setting": {
"tabs": {

View File

@ -66,7 +66,7 @@ export interface KeyTap extends KeyBase {
}
export type KeyMacroList = Array<{
type: "touch" | "sleep" | "swipe" | "input-text";
type: "touch" | "sleep" | "swipe" | "key-input-mode";
args: any[];
}> | null;

View File

@ -27,8 +27,6 @@ export const useGlobalStore = defineStore("global", () => {
const controledDevice: Ref<ControledDevice | null> = ref(null);
const editKeyMappingList: Ref<KeyMapping[]> = ref([]);
const showInputBox: (_: boolean) => void = (_: boolean) => {};
let checkUpdate: () => Promise<void> = async () => {};
let checkAdb: () => Promise<void> = async () => {};
@ -75,6 +73,8 @@ export const useGlobalStore = defineStore("global", () => {
const screenSizeW: Ref<number> = ref(0);
const screenSizeH: Ref<number> = ref(0);
const keyInputFlag = ref(false);
// persistent storage
const keyMappingConfigList: Ref<KeyMappingConfig[]> = ref([]);
const curKeyMappingIndex = ref(0);
@ -94,12 +94,12 @@ export const useGlobalStore = defineStore("global", () => {
// in-memory storage
screenSizeW,
screenSizeH,
keyInputFlag,
showLoading,
hideLoading,
showLoadingRef,
controledDevice,
editKeyMappingList,
showInputBox,
applyEditKeyMappingList,
resetEditKeyMappingList,
setKeyMappingIndex,