mpv
mpv copied to clipboard
Toggle console with a single key
Currently - to open console you have to press 2 keys, its not a toggle. Is there any way to make it show and hide console by only one key?
mp.add_forced_key_binding("esc", nil, function()
mp.commandv("script-binding", "console/enable")
end)
With that you can open and close the console with escape.
Copy that text into a .lua file in your scripts folder.
^ and this wouldn't work in input.conf?
^ and this wouldn't work in
input.conf?
No, I tried it in input.conf first, but apparently it has to be a forced key bind to overwrite the escape key.
But other keys work as expected here for the console toggle?
The console uses escape for closing it, and you can't change that without changing the code. And so if the goal is toggling, and closing has to be escape, then opening also has to be escape.
So complicated, for what? the stats (frame dropped and etc) is a toggle, why cant console be the same?
mp.add_forced_key_binding("esc", nil, function() mp.commandv("script-binding", "console/enable") end)With that you can open and close the console with escape.
Copy that text into a
.luafile in your scripts folder.
The thing is - I don't want to use escape key as the toggle, let's say I want to use g (example), it doesn't work.
~Alternatively you make a PR to add a binding for disabling to the console, analogous to it's enable binding. Then you can use any key binding for toggling that does not get overwritten when console is open. You can find the key bindings that get enabled upon opening the console here.~
Edit: Actually that wouldn't work. I guess you could add a binding specifically for toggling.
~~Not sure what the commotion is about, you can easily bind it to the key you want. Here's what I use:~~
F9 script-binding console/enable
Edit: nevermind
This was discussed in https://github.com/mpv-player/mpv/pull/10075#issuecomment-1097343116.
I thought that if the console enabled and disabled an input section instead of binding and unbinding the keybindings on open and close, you could add bindings like TAB {console} keypress ESC. But I later noticed that rossy's original script at https://github.com/rossy/mpv-repl/blob/master/repl.lua did use input sections, and wm4 removed them when merging it, which must be because he deprecated input sections, though with him gone most likely no one is going to remove them. So I'm hesitant about restoring them. And even with an input section you could only invoke other keypresses and not console.lua's functions directly, though they could be converted to script messages.
He actually forgot to remove the line mp.enable_key_bindings('console-input', 'allow-hide-cursor+allow-vo-dragging') so you can add {console-input} keybindings, as long as they're not the same as other console.lua keybindings since it uses add_forced_key_binding, but they are never disabled, e.g.
F1 script-binding console/enable
F1 {console-input} keypress esc
Pressing F1 twice toggles the console but pressing it again no longer enables it.
because he deprecated input sections
what is the supposed replacement to these?
There is no replacement, you should keep using input sections since the developer that wanted to remove them left.
You can just use this script actually:
local open = false
mp.add_key_binding('F1', function ()
mp.commandv('script-message-to', 'console', open and 'disable' or 'enable')
open = not open
end)
@guidocella Does this script example also work with
[input] Key ` is bound to:
[input] 1. 'script-binding console/enable' in <builtin>:1 (default)
(i.e. the standard console key), or does this break something else?
Edit
Here's what I meant:
local openconsole = false
mp.add_key_binding('`', function ()
mp.commandv('script-message-to', 'console', openconsole and 'disable' or 'enable')
openconsole = not openconsole
end)
You can just use this script actually:
Since I use input-default-bindings=no, I need to add this to input.conf, but how?
Nope it only works with keys not bound by console.lua.
Scripts go in .lua files in in the scripts directory, not in input.conf.
Scripts go in .lua files
Sorry, I might have given you the wrong idea, I know .lua files go in scripts folder,
I'm asking how I can call this function using input.conf?
I did create a .lua file called console-toggle and I want to call it since I use input-default-bindings=no therefor any key from any script doesn't do anything.
Nvm, it's F1 script-binding console_toggle/__keybinding1
Just give a name to the binding as the second argument
local open = false
mp.add_key_binding(nil, 'toggle-console', function ()
mp.commandv('script-message-to', 'console', open and 'disable' or 'enable')
open = not open
end)
and bind script-message toggle-console
Finally I think I can close this issue, thank you!