Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Non latin keyboard layout support player shortcut (#5684)

Wicklow2c525a5466c1
diff --git a/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts b/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts
index f5b4b3919f..2742b21a1c 100644
--- a/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts
+++ b/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts
@@ -218,12 +218,37 @@ class PeerTubeHotkeysPlugin extends Plugin {
}
private isNaked (event: KeyboardEvent, key: string) {
- return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && event.key === key)
+ if (key.length === 1) key = key.toUpperCase()
+
+ return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && this.getLatinKey(event.key, event.code) === key)
}
private isNakedOrShift (event: KeyboardEvent, key: string) {
return (!event.ctrlKey && !event.altKey && !event.metaKey && event.key === key)
}
+
+ // Thanks Maciej Krawczyk
+ // https://stackoverflow.com/questions/70211837/keyboard-shortcuts-commands-on-non-latin-alphabet-keyboards-javascript?rq=1
+ private getLatinKey (key: string, code: string) {
+ if (key.length !== 1) {
+ return key
+ }
+
+ const capitalHetaCode = 880
+ const isNonLatin = key.charCodeAt(0) >= capitalHetaCode
+
+ if (isNonLatin) {
+ if (code.indexOf('Key') === 0 && code.length === 4) { // i.e. 'KeyW'
+ return code.charAt(3)
+ }
+
+ if (code.indexOf('Digit') === 0 && code.length === 6) { // i.e. 'Digit7'
+ return code.charAt(5)
+ }
+ }
+
+ return key.toUpperCase()
+ }
}
videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin)