From effcf644d18b39f82ec455af3fbb673189f17ffd Mon Sep 17 00:00:00 2001 From: taoky Date: Tue, 19 Mar 2024 19:42:16 +0800 Subject: [PATCH] web_netcat: implement copy with Ctrl + Shift + C By default, modern browsers might start devtools when users press Ctrl + Shift + C. This commit prevents this behavior and do the copy with execCommand. --- web_netcat/static/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web_netcat/static/index.html b/web_netcat/static/index.html index 5a9229b..b6f042d 100644 --- a/web_netcat/static/index.html +++ b/web_netcat/static/index.html @@ -25,6 +25,16 @@ letterSpacing: 0, fontFamily: 'monospace', }); + term.attachCustomKeyEventHandler((e) => { + // Ctrl + Shift + C, to prevent browser from opening devtools + if (e.ctrlKey && e.shiftKey && e.keyCode == 67) { + e.preventDefault(); + const success = document.execCommand('copy'); + if (!success) { + console.error('Failed to copy to clipboard'); + } + } + }); const fitAddon = new FitAddon.FitAddon(); term.loadAddon(fitAddon); term.open(document.getElementById("terminal"));