Plugin: Key Handler
KeyHandlerPlugin (id 'key-handler', the same id as the kit base and the music player’s subclass) is nomercy-video-player’s desktop keyboard-binding set, a subclass of the kit’s KeyHandlerPlugin (scope resolution, cooldown, input-field awareness, bind/unbind/replace) that adds every video-specific binding as its own small, individually-overridable group method. TvKeyHandlerPlugin subclasses this one for remote-control input; Recipe: Customizing Keyboard Shortcuts covers extending or replacing bindings on either.
Options
Same KeyHandlerOptions the kit plugin accepts, scope, bindings, extend, when, cooldownMs, disableMediaControls, see Plugin: Key Handler (core) for the full table. This subclass adds no new option fields, only more default groups.
Default bindings
| Keys | Action |
|---|---|
Space | Toggle playback. |
MediaPlay / MediaPause / MediaPlayPause / MediaStop / MediaRewind / MediaFastForward | Hardware media keys. Gated by disableMediaControls (config field, not the plugin option) via mediaControlsAllowed(). |
ArrowLeft / ArrowRight | Rewind / forward one default step. Desktop only, isTv() gates this off, see Plugin: TV Key Handler for the TV equivalent. |
ArrowUp / ArrowDown | Volume up / down. Desktop only (!isTv() && !isMobile()). |
m | Toggle mute. |
Subtitle, 5, v | Cycle subtitle tracks. |
Audio, 2, b | Cycle audio tracks. |
shift+ArrowLeft / shift+ArrowRight | Seek ±3s (VLC-style modifier seek). |
alt+ArrowLeft / alt+ArrowRight | Seek ±10s. |
ctrl+ArrowLeft / ctrl+ArrowRight | Seek ±60s. |
1 / 3 / 6 / 9 | Quick-skip forward 120s / 30s / 60s / 90s. |
ColorF0Red / ColorF1Green / ColorF2Yellow / ColorF3Blue | TV remote color buttons, forward 30s / 60s / 90s / 120s. |
MediaTrackNext / MediaTrackPrevious | Next / previous item. Gated by disableMediaControls. |
n / p | Next / previous item. Not gated. |
shift+n / shift+p | Next / previous chapter. |
f / F11 | Toggle fullscreen. |
Escape | Exit fullscreen, only when currently active. |
] / [ | Speed up / down one step through playbackRates(). |
= | Reset speed to 1x. |
e | Frame-advance (~1 frame at 30fps). Skipped while playing or loading, so it fires while paused, idle, or stopped. |
t | Show current / remaining time as an OSD message. |
+ / shift++ / - | Emit subtitle-size-up / subtitle-size-down. No shipped plugin listens, wire your own listener (or a custom overlay) to step subtitleStyle().fontSize. |
a / BrowserFavorites | Cycle aspect ratio. |
s | Stop. |
shift+? | Calls DesktopUiPlugin.toggleShortcuts() directly via getPlugin() (opens the shortcuts overlay when that plugin is mounted, no-ops otherwise). |
Rules & restrictions
- Every group above is its own
protectedmethod (addPlaybackKeys,addVolumeKeys,addFullscreenKeys, and so on), called fromaddDefaults(). Overriding one group in a subclass leaves the rest untouched. disableControlsonVideoPlayerConfigshort-circuitsaddDefaults()entirely, no group runs, only bindings your ownuse()override adds exist.disableMediaControls(also onVideoPlayerConfig) only gates the hardwareMediaXbindings and theMediaTrackNext/Previouspair, it does not touchSpace, arrows, or any letter-key binding.shift+?is bound as'shift+?', not'?', because on standard keyboards pressing?sendskey='?'withshiftKey=true; the kit’s combo canonicalizer folds modifier state into the key string, so binding the literal'?'would never match the real event.
How to extend it
import nmplayer from '@nomercy-entertainment/nomercy-video-player';
import { KeyHandlerPlugin } from '@nomercy-entertainment/nomercy-video-player';
const player = nmplayer('player');
class MyKeyHandler extends KeyHandlerPlugin {
protected override addFullscreenKeys(): void {
this.bind('f', () => { void this.player.toggleFullscreen(); });
// F11 and Escape from the default binding intentionally dropped.
}
}
player.addPlugin(MyKeyHandler);
See Recipe: Customizing Keyboard Shortcuts for the full range of options, from one runtime bind() call up to overriding addDefaults() entirely.
Next steps
- Plugin: TV Key Handler: the remote-control subclass built on this one.