Skip to content

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

KeysAction
SpaceToggle playback.
MediaPlay / MediaPause / MediaPlayPause / MediaStop / MediaRewind / MediaFastForwardHardware media keys. Gated by disableMediaControls (config field, not the plugin option) via mediaControlsAllowed().
ArrowLeft / ArrowRightRewind / forward one default step. Desktop only, isTv() gates this off, see Plugin: TV Key Handler for the TV equivalent.
ArrowUp / ArrowDownVolume up / down. Desktop only (!isTv() && !isMobile()).
mToggle mute.
Subtitle, 5, vCycle subtitle tracks.
Audio, 2, bCycle audio tracks.
shift+ArrowLeft / shift+ArrowRightSeek ±3s (VLC-style modifier seek).
alt+ArrowLeft / alt+ArrowRightSeek ±10s.
ctrl+ArrowLeft / ctrl+ArrowRightSeek ±60s.
1 / 3 / 6 / 9Quick-skip forward 120s / 30s / 60s / 90s.
ColorF0Red / ColorF1Green / ColorF2Yellow / ColorF3BlueTV remote color buttons, forward 30s / 60s / 90s / 120s.
MediaTrackNext / MediaTrackPreviousNext / previous item. Gated by disableMediaControls.
n / pNext / previous item. Not gated.
shift+n / shift+pNext / previous chapter.
f / F11Toggle fullscreen.
EscapeExit fullscreen, only when currently active.
] / [Speed up / down one step through playbackRates().
=Reset speed to 1x.
eFrame-advance (~1 frame at 30fps). Skipped while playing or loading, so it fires while paused, idle, or stopped.
tShow 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 / BrowserFavoritesCycle aspect ratio.
sStop.
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 protected method (addPlaybackKeys, addVolumeKeys, addFullscreenKeys, and so on), called from addDefaults(). Overriding one group in a subclass leaves the rest untouched.
  • disableControls on VideoPlayerConfig short-circuits addDefaults() entirely, no group runs, only bindings your own use() override adds exist.
  • disableMediaControls (also on VideoPlayerConfig) only gates the hardware MediaX bindings and the MediaTrackNext/Previous pair, it does not touch Space, arrows, or any letter-key binding.
  • shift+? is bound as 'shift+?', not '?', because on standard keyboards pressing ? sends key='?' with shiftKey=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

TypeScript
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