How to Bind One Key to Multiple Actions in mpv?

This article provides a concise guide on how to configure the mpv media player to execute multiple commands sequentially using a single keypress. While mpv does not natively support multi-command chaining through standard syntax in its default configuration file, you can easily achieve this behavior by utilizing the cycle-values command or by writing a short Lua script. Below, we explore both methods so you can automate your playback controls efficiently.

Method 1: Using the cycle-values Trick

For simple sequential actions that do not require complex logic, you can abuse the built-in cycle-values command in your input.conf file. By routing a single command through a dummy or temporary state, you can trick mpv into executing a sequence.

To do this, open your input.conf file and use the following format:

k cycle-values speed 1.5 1.0 ; show-text "Speed Toggled"

Note: The semicolon (;) acts as a command separator in mpv’s input system, allowing you to string certain commands together on a single line. However, this native chaining has limitations depending on the specific commands used.

The most reliable and robust way to bind multiple sequential actions to a single key is by creating a lightweight Lua script. This method bypasses any syntax limitations of the input.conf file.

  1. Navigate to your mpv configuration directory and open the scripts folder (create it if it doesn’t exist).
  2. Create a new text file named multi_bind.lua.
  3. Paste the following code into the file:
local mp = require 'mp'

local function my_sequence()
    -- Action 1: Pause the video
    mp.set_property("pause", "yes")
    -- Action 2: Show a custom OSD message
    mp.osd_message("Playback Paused - Checking Status")
    -- Action 3: Take a screenshot
    mp.command("screenshot")
end

-- Bind the sequence to the "ctrl+x" key
mp.add_forced_key_bind("ctrl+x", "sequence_binding", my_sequence)

Save the file and restart mpv. Pressing Ctrl + X will now instantly pause the video, display your text, and take a screenshot in exact sequential order. You can modify the mp.command and property blocks inside the function to execute any combination of mpv actions you require.