feat: support Mac copy/paste

This commit is contained in:
xianshenglu 2023-11-12 22:53:13 +08:00
parent 8413040f0d
commit df5e09f579
2 changed files with 17 additions and 6 deletions

View File

@ -85,8 +85,9 @@ export default class Keyboard {
_handleKeyDown(e) {
const code = this._getKeyCode(e);
const isCtrlVEvent = code === "KeyV" && e.ctrlKey;
if (isCtrlVEvent) {
const isPasteKeydownEvent = (browser.isWindows() && code === "KeyV" && e.ctrlKey)
|| (browser.isMac() && code === "KeyV" && e.metaKey);
if (isPasteKeydownEvent) {
return;
}
let keysym = KeyboardUtil.getKeysym(e);

View File

@ -36,6 +36,7 @@ import TightDecoder from "./decoders/tight.js";
import TightPNGDecoder from "./decoders/tightpng.js";
import ZRLEDecoder from "./decoders/zrle.js";
import JPEGDecoder from "./decoders/jpeg.js";
import * as browser from "./util/browser.js";
// How many seconds to wait for a disconnect to finish
const DISCONNECT_TIMEOUT = 3;
@ -504,10 +505,19 @@ export default class RFB extends EventTargetMixin {
if (shouldUpdateRemoteClipboard) {
this.clipboardPasteFrom(text);
}
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", true);
this.sendKey(KeyTable.XK_V, "KeyV", true);
this.sendKey(KeyTable.XK_V, "KeyV", false);
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", false);
if (browser.isMac()) {
this.sendKey(KeyTable.XK_Meta_L, "Meta", true);
this.sendKey(KeyTable.XK_V, "KeyV", true);
this.sendKey(KeyTable.XK_V, "KeyV", false);
this.sendKey(KeyTable.XK_Meta_L, "Meta", false);
return;
}
if (browser.isWindows()) {
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", true);
this.sendKey(KeyTable.XK_V, "KeyV", true);
this.sendKey(KeyTable.XK_V, "KeyV", false);
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", false);
}
}
clipboardPasteFrom(text) {