feat: 为vnc添加输入框功能
This commit is contained in:
@@ -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<any | null>(null);
|
||||
const mouse = ref<any | null>(null);
|
||||
// Initialize desiredModalWidth and desiredModalHeight from store or defaults
|
||||
@@ -614,8 +650,31 @@ const stopResize = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-2 border-t border-border flex-shrink-0 text-xs text-text-secondary bg-header flex items-center justify-end">
|
||||
<div class="flex items-center space-x-2 flex-wrap gap-y-1">
|
||||
<div class="p-2 border-t border-border flex-shrink-0 text-xs text-text-secondary bg-header flex items-center justify-between flex-wrap gap-y-2">
|
||||
<!-- 输入框和发送按钮 -->
|
||||
<div class="flex items-center space-x-2 flex-auto mr-0 sm:mr-4"> <!-- flex-auto to grow, responsive margin -->
|
||||
<input
|
||||
type="text"
|
||||
v-model="vncPasteInputText"
|
||||
:placeholder="t('vncModal.textInputPlaceholder')"
|
||||
class="flex-grow px-2 py-1 text-xs border border-border rounded bg-input text-foreground focus:outline-none focus:ring-1 focus:ring-primary min-w-0"
|
||||
style="min-width: 120px;"
|
||||
@focus="disableVncKeyboard"
|
||||
@blur="enableVncKeyboard"
|
||||
@keydown.enter.prevent="sendInputTextToVnc"
|
||||
/>
|
||||
<button
|
||||
@click="sendInputTextToVnc"
|
||||
:disabled="!vncPasteInputText.trim() || connectionStatus !== 'connected'"
|
||||
class="px-3 py-1 bg-primary text-white rounded text-xs hover:bg-primary-dark disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap"
|
||||
:title="t('vncModal.sendButtonTitle')"
|
||||
>
|
||||
{{ t('common.send') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 现有的宽度/高度和重新连接按钮 -->
|
||||
<div class="flex items-center space-x-2 flex-wrap gap-y-1 flex-shrink-0">
|
||||
<label for="modal-width" class="text-xs ml-2">{{ t('common.width') }}:</label>
|
||||
<input
|
||||
id="modal-width"
|
||||
|
||||
@@ -961,7 +961,8 @@
|
||||
"sortAscending": "Ascending",
|
||||
"sortDescending": "Descending",
|
||||
"restore": "Restore",
|
||||
"minimize": "Minimize"
|
||||
"minimize": "Minimize",
|
||||
"send":"Send"
|
||||
},
|
||||
"layoutConfigurator": {
|
||||
"title": "Layout Configurator",
|
||||
@@ -1100,7 +1101,12 @@
|
||||
"reconnectTooltip": "Reconnect to the remote desktop"
|
||||
},
|
||||
"vncModal": {
|
||||
"title": "VNC Session"
|
||||
"title": "VNC Session",
|
||||
"textInputPlaceholder": "Enter text here to send to VNC",
|
||||
"sendButtonTitle": "Send text to VNC (simulates keyboard input)",
|
||||
"errors": {
|
||||
"simulateInputError": "Error simulating keyboard input: {error}"
|
||||
}
|
||||
},
|
||||
"commandInputBar": {
|
||||
"placeholder": "Enter command and press Enter to send...",
|
||||
|
||||
@@ -103,7 +103,8 @@
|
||||
"testing": "テスト中...",
|
||||
"width": "幅",
|
||||
"restore": "元に戻す",
|
||||
"minimize": "最小化"
|
||||
"minimize": "最小化",
|
||||
"send":"送信する"
|
||||
},
|
||||
"connections": {
|
||||
"actions": {
|
||||
@@ -696,7 +697,12 @@
|
||||
"titlePlaceholder": "リモートデスクトップ接続"
|
||||
},
|
||||
"vncModal": {
|
||||
"title": "VNCセッション"
|
||||
"title": "VNCセッション",
|
||||
"textInputPlaceholder": "VNC に送信するテキストをここに入力",
|
||||
"sendButtonTitle": "VNC にテキストを送信 (キーボード入力をシミュレート)",
|
||||
"errors": {
|
||||
"simulateInputError": "キーボード入力のシミュレート中にエラーが発生しました: {error}"
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"popupFileManager": {
|
||||
|
||||
@@ -962,7 +962,8 @@
|
||||
"sortAscending": "升序",
|
||||
"sortDescending": "降序",
|
||||
"restore": "还原",
|
||||
"minimize": "最小化"
|
||||
"minimize": "最小化",
|
||||
"send":"发送"
|
||||
},
|
||||
"layoutConfigurator": {
|
||||
"title": "布局管理器",
|
||||
@@ -1103,7 +1104,12 @@
|
||||
"reconnectTooltip": "重新连接到远程桌面"
|
||||
},
|
||||
"vncModal": {
|
||||
"title": "VNC 会话"
|
||||
"title": "VNC 会话",
|
||||
"textInputPlaceholder": "在此输入文本以发送到 VNC",
|
||||
"sendButtonTitle": "将文本发送到 VNC (模拟键盘输入)",
|
||||
"errors": {
|
||||
"simulateInputError": "模拟键盘输入时出错: {error}"
|
||||
}
|
||||
},
|
||||
"commandInputBar": {
|
||||
"placeholder": "在此输入命令后按 Enter 发送到终端...",
|
||||
|
||||
Reference in New Issue
Block a user