fixed mac os keyboard mapping. (#84)

This commit is contained in:
Miroslav Šedivý 2021-07-17 11:56:16 +02:00 committed by GitHub
parent 38bed98741
commit ffcca402ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 2 deletions

View File

@ -64,6 +64,7 @@ For n.eko room management software visit https://github.com/m1k1o/neko-rooms.
- Respecting `NEKO_DEBUG` env variable. - Respecting `NEKO_DEBUG` env variable.
- Fullscreen support for iOS devices. - Fullscreen support for iOS devices.
- Added `chrome-sandbox` to fix weird bug when chromium didn't start. - 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 ### Misc
- Custom docker workflow. - Custom docker workflow.

View File

@ -415,7 +415,7 @@
return true return true
} }
this.$client.sendData('keydown', { key }) this.$client.sendData('keydown', { key: this.keyMap(key) })
return false return false
} }
this.keyboard.onkeyup = (key: number) => { this.keyboard.onkeyup = (key: number) => {
@ -423,7 +423,7 @@
return return
} }
this.$client.sendData('keyup', { key }) this.$client.sendData('keyup', { key: this.keyMap(key) })
} }
this.keyboard.listenTo(this._overlay) this.keyboard.listenTo(this._overlay)
} }
@ -435,6 +435,51 @@
/* Guacamole Keyboard does not provide destroy functions */ /* 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() { play() {
if (!this._video.paused || !this.playable) { if (!this._video.paused || !this.playable) {
return return