From ffcca402ef479c2dd8ddd6f530500017a27ea796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 17 Jul 2021 11:56:16 +0200 Subject: [PATCH] fixed mac os keyboard mapping. (#84) --- README.md | 1 + client/src/components/video.vue | 49 +++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b350439..203103ce 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ For n.eko room management software visit https://github.com/m1k1o/neko-rooms. - Respecting `NEKO_DEBUG` env variable. - Fullscreen support for iOS devices. - Added `chrome-sandbox` to fix weird bug when chromium didn't start. +- Fixed keyboard mapping on macOS, when CMD could not be used for copy & paste. ### Misc - Custom docker workflow. diff --git a/client/src/components/video.vue b/client/src/components/video.vue index f9d1e388..593e6756 100644 --- a/client/src/components/video.vue +++ b/client/src/components/video.vue @@ -415,7 +415,7 @@ return true } - this.$client.sendData('keydown', { key }) + this.$client.sendData('keydown', { key: this.keyMap(key) }) return false } this.keyboard.onkeyup = (key: number) => { @@ -423,7 +423,7 @@ return } - this.$client.sendData('keyup', { key }) + this.$client.sendData('keyup', { key: this.keyMap(key) }) } this.keyboard.listenTo(this._overlay) } @@ -435,6 +435,51 @@ /* Guacamole Keyboard does not provide destroy functions */ } + get hasMacOSKbd() { + return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) + } + + KeyTable = { + XK_ISO_Level3_Shift: 0xfe03, // AltGr + XK_Mode_switch: 0xff7e, // Character set switch + XK_Control_L: 0xffe3, // Left control + XK_Control_R: 0xffe4, // Right control + XK_Meta_L: 0xffe7, // Left meta + XK_Meta_R: 0xffe8, // Right meta + XK_Alt_L: 0xffe9, // Left alt + XK_Alt_R: 0xffea, // Right alt + XK_Super_L: 0xffeb, // Left super + XK_Super_R: 0xffec, // Right super + } + + keyMap(key: number): number { + // Alt behaves more like AltGraph on macOS, so shuffle the + // keys around a bit to make things more sane for the remote + // server. This method is used by noVNC, RealVNC and TigerVNC + // (and possibly others). + if (this.hasMacOSKbd) { + switch (key) { + case this.KeyTable.XK_Meta_L: + key = this.KeyTable.XK_Control_L + break + case this.KeyTable.XK_Super_L: + key = this.KeyTable.XK_Alt_L + break + case this.KeyTable.XK_Super_R: + key = this.KeyTable.XK_Super_L + break + case this.KeyTable.XK_Alt_L: + key = this.KeyTable.XK_Mode_switch + break + case this.KeyTable.XK_Alt_R: + key = this.KeyTable.XK_ISO_Level3_Shift + break + } + } + + return key + } + play() { if (!this._video.paused || !this.playable) { return