console.lua: flush keybinds before sending mp.input opened events

This commit uses the undocumented `mp.flush_keybindings()` method
to ensure that all `console.lua` keybinds are set before
sending the `opened` event to `mp.input` clients.

Previously, the keybinds would only be flushed when `console.lua` went
idle. As the `opened` event is sent before this happens, clients
processing the event may end up flushing their own keybinds before this
happens. This makes it unreliable to use the `opened` event to override
keybinds set by `console.lua`; for example, adding different
behaviour to `input.select` when using `Shift+Enter` instead of `Enter`.

This commit allows the `opened` callback to be used to safely override
`console.lua` keybinds.

.luacheckrc: move flush_keybindings to globals
This commit is contained in:
CogentRedTester authored and Kacper Michajłow committed 2026-02-24 20:12:57 +01:00
1 parent e09a1d12f2
commit 0af0c137bb
2 files changed
+5 -1

No files matched your search

+1 -1
View File
@@ -57,6 +57,7 @@ local mp_globals = {
disable_key_bindings = {}, disable_key_bindings = {},
enable_key_bindings = {}, enable_key_bindings = {},
find_config_file = {}, find_config_file = {},
flush_keybindings = {},
format_time = {}, format_time = {},
get_mouse_pos = {}, get_mouse_pos = {},
set_key_bindings = {}, set_key_bindings = {},
@@ -78,7 +79,6 @@ local mp_internal = {
UNKNOWN_TYPE = { fields = { info = {}, type = {} }}, UNKNOWN_TYPE = { fields = { info = {}, type = {} }},
_legacy_overlay = { fields = { res_x = {}, res_y = {}, data = {}, update = {} }}, _legacy_overlay = { fields = { res_x = {}, res_y = {}, data = {}, update = {} }},
cancel_timer = {}, cancel_timer = {},
flush_keybindings = {},
get_osd_margins = {}, get_osd_margins = {},
input_define_section = {}, input_define_section = {},
input_disable_section = {}, input_disable_section = {},
+4
View File
@@ -1730,6 +1730,10 @@ mp.register_script_message("get-input", function (args)
end end
set_active(true) set_active(true)
-- We want to ensure the keybindings have been set before sending the "opened" event
-- in case scripts want to override our bindings.
mp.flush_keybindings()
mp.commandv("script-message-to", input_caller, input_caller_handler, "opened") mp.commandv("script-message-to", input_caller, input_caller_handler, "opened")
end) end)