From 1e7e9d1c046798e8821f3ab6f4f86128cab738d5 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Wed, 14 May 2025 20:56:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BAvnc=E6=B7=BB=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/components/VncModal.vue | 63 ++++++++++++++++++- packages/frontend/src/locales/en-US.json | 10 ++- packages/frontend/src/locales/ja-JP.json | 10 ++- packages/frontend/src/locales/zh-CN.json | 10 ++- 4 files changed, 85 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/components/VncModal.vue b/packages/frontend/src/components/VncModal.vue index 4c7204f..7f3ca37 100644 --- a/packages/frontend/src/components/VncModal.vue +++ b/packages/frontend/src/components/VncModal.vue @@ -30,6 +30,42 @@ const resizeStartY = ref(0); const initialModalWidthForResize = ref(0); const initialModalHeightForResize = ref(0); const statusMessage = ref(''); +const vncPasteInputText = ref(''); + +const sendInputTextToVnc = async () => { + if (!guacClient.value || connectionStatus.value !== 'connected') { + console.warn('[VncModal] Guacamole client not available or not connected to send text.'); + // Можно добавить сообщение для пользователя здесь, если нужно + return; + } + const textToSend = vncPasteInputText.value; + if (!textToSend) { + console.log('[VncModal] Paste input is empty, nothing to send.'); + return; + } + + console.log(`[VncModal] Simulating keyboard input for: ${textToSend.substring(0,50)}...`); + try { + for (const char of textToSend) { + const keysym = char.charCodeAt(0); //直接使用字符的 Unicode 码点作为 keysym + + // 确保 keysym 是一个有效的数字,尽管 charCodeAt(0) 总是返回数字 + if (typeof keysym === 'number' && !isNaN(keysym)) { + guacClient.value.sendKeyEvent(1, keysym); // Key press + await new Promise(resolve => setTimeout(resolve, 20)); // 短暂延迟 + guacClient.value.sendKeyEvent(0, keysym); // Key release + await new Promise(resolve => setTimeout(resolve, 30)); // 短暂延迟 + } else { + console.warn(`[VncModal] Invalid keysym for character "${char}". Skipping.`); + } + } + console.log('[VncModal] Finished simulating keyboard input.'); + // vncPasteInputText.value = ''; // 如果希望发送后清空输入框,取消此行注释 + } catch (err: any) { + console.error('[VncModal] Error simulating keyboard input:', err); + statusMessage.value = t('vncModal.errors.simulateInputError', { error: err.message }); + } +}; const keyboard = ref(null); const mouse = ref(null); // Initialize desiredModalWidth and desiredModalHeight from store or defaults @@ -614,8 +650,31 @@ const stopResize = () => { -
-
+
+ +
+ + +
+ + +