mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2024-11-14 22:01:55 +08:00
style(sendKey): simplify the code
This commit is contained in:
parent
83f097fbf0
commit
a55c28ffc8
@ -14,18 +14,12 @@ import { KeyMappingConfig, 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 {
|
import { sendSetClipboard } from "../frontcommand/controlMsg";
|
||||||
sendInjectKeycode,
|
|
||||||
sendSetClipboard,
|
|
||||||
} from "../frontcommand/controlMsg";
|
|
||||||
import { getCurrent, PhysicalSize } from "@tauri-apps/api/window";
|
import { getCurrent, PhysicalSize } from "@tauri-apps/api/window";
|
||||||
import {
|
import { AndroidKeycode } from "../frontcommand/android";
|
||||||
AndroidKeyEventAction,
|
|
||||||
AndroidKeycode,
|
|
||||||
AndroidMetastate,
|
|
||||||
} from "../frontcommand/android";
|
|
||||||
import { Store } from "@tauri-apps/plugin-store";
|
import { Store } from "@tauri-apps/plugin-store";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { SendKeyAction, sendKey } from "../frontcommand/scrcpyMaskCmd";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
@ -203,18 +197,9 @@ async function pasteText() {
|
|||||||
});
|
});
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
// send enter
|
// send enter
|
||||||
await sendInjectKeycode({
|
await sendKey({
|
||||||
action: AndroidKeyEventAction.AKEY_EVENT_ACTION_DOWN,
|
action: SendKeyAction.Default,
|
||||||
keycode: AndroidKeycode.AKEYCODE_ENTER,
|
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,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,17 +15,11 @@ import {
|
|||||||
import { Keyboard24Regular } from "@vicons/fluent";
|
import { Keyboard24Regular } from "@vicons/fluent";
|
||||||
import { NIcon, useMessage } from "naive-ui";
|
import { NIcon, useMessage } from "naive-ui";
|
||||||
import { useGlobalStore } from "../store/global";
|
import { useGlobalStore } from "../store/global";
|
||||||
import {
|
import { sendSetScreenPowerMode } from "../frontcommand/controlMsg";
|
||||||
sendInjectKeycode,
|
import { AndroidKeycode } from "../frontcommand/android";
|
||||||
sendSetScreenPowerMode,
|
|
||||||
} from "../frontcommand/controlMsg";
|
|
||||||
import {
|
|
||||||
AndroidKeyEventAction,
|
|
||||||
AndroidKeycode,
|
|
||||||
AndroidMetastate,
|
|
||||||
} from "../frontcommand/android";
|
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { SendKeyAction, sendKey } from "../frontcommand/scrcpyMaskCmd";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -39,28 +33,11 @@ function nav(name: string) {
|
|||||||
router.replace({ name });
|
router.replace({ name });
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep(time: number) {
|
|
||||||
return new Promise<void>((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve();
|
|
||||||
}, time);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendKeyCodeToDevice(code: AndroidKeycode) {
|
async function sendKeyCodeToDevice(code: AndroidKeycode) {
|
||||||
if (store.controledDevice) {
|
if (store.controledDevice) {
|
||||||
await sendInjectKeycode({
|
await sendKey({
|
||||||
action: AndroidKeyEventAction.AKEY_EVENT_ACTION_DOWN,
|
action: SendKeyAction.Default,
|
||||||
keycode: code,
|
keycode: code,
|
||||||
repeat: 0,
|
|
||||||
metastate: AndroidMetastate.AMETA_NONE,
|
|
||||||
});
|
|
||||||
await sleep(50);
|
|
||||||
await sendInjectKeycode({
|
|
||||||
action: AndroidKeyEventAction.AKEY_EVENT_ACTION_UP,
|
|
||||||
keycode: code,
|
|
||||||
repeat: 0,
|
|
||||||
metastate: AndroidMetastate.AMETA_NONE,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
message.error(t("sidebar.noControledDevice"));
|
message.error(t("sidebar.noControledDevice"));
|
||||||
|
@ -35,7 +35,7 @@ export enum ScrcpyMaskCmdType {
|
|||||||
|
|
||||||
type ScrcpyMaskCmdData = CmdDataSendKey | CmdDataTouch | CmdDataSwipe | String;
|
type ScrcpyMaskCmdData = CmdDataSendKey | CmdDataTouch | CmdDataSwipe | String;
|
||||||
|
|
||||||
enum SendKeyAction {
|
export enum SendKeyAction {
|
||||||
Default = 0,
|
Default = 0,
|
||||||
Down = 1,
|
Down = 1,
|
||||||
Up = 2,
|
Up = 2,
|
||||||
|
Loading…
Reference in New Issue
Block a user