mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-08-29 10:21:34 +00:00
40 lines
1021 B
TypeScript
40 lines
1021 B
TypeScript
import Guacamole from "guacamole-common-js";
|
|
|
|
const CONTROL_LEFT_KEYSYM = 0xffe3;
|
|
const V_KEYSYM = 0x76;
|
|
|
|
interface ClipboardOutputStream {
|
|
sendBlob(data: string): void;
|
|
sendEnd(): void;
|
|
}
|
|
|
|
export interface GuacamoleClipboardClient {
|
|
createClipboardStream(mimetype: string): ClipboardOutputStream;
|
|
sendKeyEvent(pressed: number, keysym: number): void;
|
|
}
|
|
|
|
export function isPasteShortcut(
|
|
event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "key" | "metaKey">,
|
|
): boolean {
|
|
return (
|
|
!event.altKey &&
|
|
(event.ctrlKey || event.metaKey) &&
|
|
event.key.toLowerCase() === "v"
|
|
);
|
|
}
|
|
|
|
export function pasteTextToRemote(
|
|
client: GuacamoleClipboardClient,
|
|
text: string,
|
|
): void {
|
|
const stream = client.createClipboardStream("text/plain");
|
|
const writer = new Guacamole.StringWriter(stream);
|
|
writer.sendText(text);
|
|
writer.sendEnd();
|
|
|
|
client.sendKeyEvent(1, CONTROL_LEFT_KEYSYM);
|
|
client.sendKeyEvent(1, V_KEYSYM);
|
|
client.sendKeyEvent(0, V_KEYSYM);
|
|
client.sendKeyEvent(0, CONTROL_LEFT_KEYSYM);
|
|
}
|