summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-19 23:10:41 +0100
committerwm4 <wm4@nowhere>2019-11-19 23:11:05 +0100
commitb08c8f50b5b1c29bd08aea8b586b6acfd680f3ce (patch)
tree35036cf2570c01a0c68cf0874c0802e4bc680c47
parent13815bf25179da6dd450141fa6c1ab67a4b00b6b (diff)
downloadmpv-b08c8f50b5b1c29bd08aea8b586b6acfd680f3ce.tar.bz2
mpv-b08c8f50b5b1c29bd08aea8b586b6acfd680f3ce.tar.xz
lua: report key name for "complex" key bindings
This might make certain use cases less of a mess.
-rw-r--r--DOCS/man/lua.rst7
-rw-r--r--player/lua/defaults.lua9
2 files changed, 9 insertions, 7 deletions
diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst
index d3034f1113..5f9525d6b6 100644
--- a/DOCS/man/lua.rst
+++ b/DOCS/man/lua.rst
@@ -253,9 +253,10 @@ The ``mp`` module is preloaded, although it can be loaded manually with
events (as well as key repeat, if enabled), with the first
argument being a table. This table has an ``event`` entry, which
is set to one of the strings ``down``, ``repeat``, ``up`` or
- ``press`` (the latter if key up/down can't be tracked). It further
- has an ``is_mouse`` entry, which tells whether the event was caused
- by a mouse button.
+ ``press`` (the latter if key up/down can't be tracked). The
+ ``is_mouse`` entry tells whether the event was caused by a mouse
+ button. The ``key_name`` entry contains the name of they key that
+ triggered this, or ``nil`` if unknown or invoked artificially.
Internally, key bindings are dispatched via the ``script-message-to`` or
``script-binding`` input commands and ``mp.register_script_message``.
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 7cf06426ff..4280d19d10 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -54,10 +54,10 @@ local function reserve_binding()
return "__keybinding" .. tostring(message_id)
end
-local function dispatch_key_binding(name, state)
+local function dispatch_key_binding(name, state, key_name)
local fn = dispatch_key_bindings[name]
if fn then
- fn(name, state)
+ fn(name, state, key_name)
end
end
@@ -176,10 +176,11 @@ local function add_binding(attrs, key, name, fn, rp)
["r"] = "repeat",
["p"] = "press",
}
- key_cb = function(name, state)
+ key_cb = function(name, state, key_name)
fn({
event = key_states[state:sub(1, 1)] or "unknown",
- is_mouse = state:sub(2, 2) == "m"
+ is_mouse = state:sub(2, 2) == "m",
+ key = key_name,
})
end
msg_cb = function()