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 = () => { -
-
+
+ +
+ + +
+ + +