mirror of
https://github.com/mpv-player/mpv
synced 2025-02-04 22:22:16 +00:00
lua: add a way to add repeatable key bindings
For these, autorepeat is enabled.
This commit is contained in:
parent
0a78a61d89
commit
00626817c8
@ -181,7 +181,7 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
|||||||
Return the current mpv internal time in seconds as a number. This is
|
Return the current mpv internal time in seconds as a number. This is
|
||||||
basically the system time, with an arbitrary offset.
|
basically the system time, with an arbitrary offset.
|
||||||
|
|
||||||
``mp.add_key_binding(key, name|fn [,fn])``
|
``mp.add_key_binding(key, name|fn [,fn [,flags]])``
|
||||||
Register callback to be run on a key binding. The binding will be mapped to
|
Register callback to be run on a key binding. The binding will be mapped to
|
||||||
the given ``key``, which is a string describing the physical key. This uses
|
the given ``key``, which is a string describing the physical key. This uses
|
||||||
the same key names as in input.conf, and also allows combinations
|
the same key names as in input.conf, and also allows combinations
|
||||||
@ -198,6 +198,10 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
|||||||
overwritten. You can omit the name, in which case a random name is generated
|
overwritten. You can omit the name, in which case a random name is generated
|
||||||
internally.
|
internally.
|
||||||
|
|
||||||
|
The last argument is used for additional flags. Currently, this includes
|
||||||
|
the string ``repeatable``, which enables key repeat for this specific
|
||||||
|
binding.
|
||||||
|
|
||||||
Internally, key bindings are dispatched via the ``script_message_to`` input
|
Internally, key bindings are dispatched via the ``script_message_to`` input
|
||||||
command and ``mp.register_script_message``.
|
command and ``mp.register_script_message``.
|
||||||
|
|
||||||
|
@ -105,8 +105,9 @@ local function update_key_bindings()
|
|||||||
local cfg = ""
|
local cfg = ""
|
||||||
for k, v in pairs(key_bindings) do
|
for k, v in pairs(key_bindings) do
|
||||||
if v.forced ~= def then
|
if v.forced ~= def then
|
||||||
cfg = cfg .. v.key .. " script_message_to " .. mp.script_name
|
local flags = (v.repeatable and " repeatable") or ""
|
||||||
.. " " .. v.name .. "\n"
|
cfg = cfg .. v.key .. " " .. flags .. " script_message_to "
|
||||||
|
.. mp.script_name .. " " .. v.name .. "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
mp.input_define_section(section, cfg, flags)
|
mp.input_define_section(section, cfg, flags)
|
||||||
@ -115,12 +116,13 @@ local function update_key_bindings()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_binding(attrs, key, name, fn)
|
local function add_binding(attrs, key, name, fn, rp)
|
||||||
if (type(name) ~= "string") and (not fn) then
|
if (type(name) ~= "string") and (not fn) then
|
||||||
fn = name
|
fn = name
|
||||||
name = "message" .. tostring(message_id)
|
name = "message" .. tostring(message_id)
|
||||||
message_id = message_id + 1
|
message_id = message_id + 1
|
||||||
end
|
end
|
||||||
|
attrs.repeatable = rp == "repeatable"
|
||||||
attrs.key = key
|
attrs.key = key
|
||||||
attrs.name = name
|
attrs.name = name
|
||||||
key_bindings[name] = attrs
|
key_bindings[name] = attrs
|
||||||
|
Loading…
Reference in New Issue
Block a user