mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
lua: report key name for "complex" key bindings
This might make certain use cases less of a mess.
This commit is contained in:
@@ -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
|
events (as well as key repeat, if enabled), with the first
|
||||||
argument being a table. This table has an ``event`` entry, which
|
argument being a table. This table has an ``event`` entry, which
|
||||||
is set to one of the strings ``down``, ``repeat``, ``up`` or
|
is set to one of the strings ``down``, ``repeat``, ``up`` or
|
||||||
``press`` (the latter if key up/down can't be tracked). It further
|
``press`` (the latter if key up/down can't be tracked). The
|
||||||
has an ``is_mouse`` entry, which tells whether the event was caused
|
``is_mouse`` entry tells whether the event was caused by a mouse
|
||||||
by a mouse button.
|
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
|
Internally, key bindings are dispatched via the ``script-message-to`` or
|
||||||
``script-binding`` input commands and ``mp.register_script_message``.
|
``script-binding`` input commands and ``mp.register_script_message``.
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ local function reserve_binding()
|
|||||||
return "__keybinding" .. tostring(message_id)
|
return "__keybinding" .. tostring(message_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dispatch_key_binding(name, state)
|
local function dispatch_key_binding(name, state, key_name)
|
||||||
local fn = dispatch_key_bindings[name]
|
local fn = dispatch_key_bindings[name]
|
||||||
if fn then
|
if fn then
|
||||||
fn(name, state)
|
fn(name, state, key_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -176,10 +176,11 @@ local function add_binding(attrs, key, name, fn, rp)
|
|||||||
["r"] = "repeat",
|
["r"] = "repeat",
|
||||||
["p"] = "press",
|
["p"] = "press",
|
||||||
}
|
}
|
||||||
key_cb = function(name, state)
|
key_cb = function(name, state, key_name)
|
||||||
fn({
|
fn({
|
||||||
event = key_states[state:sub(1, 1)] or "unknown",
|
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
|
end
|
||||||
msg_cb = function()
|
msg_cb = function()
|
||||||
|
|||||||
Reference in New Issue
Block a user