diff --git a/src/renderer/main.js b/src/renderer/main.js index 887fb4dbd0..b5415d5770 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -147,6 +147,9 @@ function onState (err, _state) { // ...same thing if you paste a torrent document.addEventListener('paste', onPaste) + // Add YouTube style hotkey shortcuts + window.addEventListener('keydown', onKeydown) + const debouncedFullscreenToggle = debounce(function () { dispatch('toggleFullScreen') }, 1000, true) @@ -507,6 +510,34 @@ function onPaste (e) { update() } +function onKeydown (e) { + const key = e.key + + if (key === 'ArrowLeft') { + dispatch('skip', -5) + } else if (key === 'ArrowRight') { + dispatch('skip', 5) + } else if (key === 'ArrowUp') { + dispatch('changeVolume', 0.1) + } else if (key === 'ArrowDown') { + dispatch('changeVolume', -0.1) + } else if (key === 'j') { + dispatch('skip', -10) + } else if (key === 'l') { + dispatch('skip', 10) + } else if (key === 'k') { + dispatch('playPause') + } else if (key === '>') { + dispatch('changePlaybackRate', 1) + } else if (key === '<') { + dispatch('changePlaybackRate', -1) + } else if (key === 'f') { + dispatch('toggleFullScreen') + } + + update() +} + function onFocus (e) { state.window.isFocused = true state.dock.badge = 0