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
2026-02-18 18:36:18 +10:30
committed by Kacper Michajłow
parent e09a1d12f2
commit 0af0c137bb
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -57,6 +57,7 @@ local mp_globals = {
disable_key_bindings = {},
enable_key_bindings = {},
find_config_file = {},
flush_keybindings = {},
format_time = {},
get_mouse_pos = {},
set_key_bindings = {},
@@ -78,7 +79,6 @@ local mp_internal = {
UNKNOWN_TYPE = { fields = { info = {}, type = {} }},
_legacy_overlay = { fields = { res_x = {}, res_y = {}, data = {}, update = {} }},
cancel_timer = {},
flush_keybindings = {},
get_osd_margins = {},
input_define_section = {},
input_disable_section = {},
+4
View File
@@ -1730,6 +1730,10 @@ mp.register_script_message("get-input", function (args)
end
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")
end)