command: support passing scale to `keypress`

This commit is contained in:
sfan5 2023-12-16 15:12:13 +01:00
parent a08e8e0b46
commit 00942d56ba
2 changed files with 9 additions and 5 deletions

View File

@ -827,11 +827,13 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
<double>
The mouse event represents double-click.
``keypress <name>``
``keypress <name> [<scale>]``
Send a key event through mpv's input handler, triggering whatever
behavior is configured to that key. ``name`` uses the ``input.conf``
naming scheme for keys and modifiers. Useful for the client API: key events
can be sent to libmpv to handle internally.
naming scheme for keys and modifiers. ``scale`` is used to scale numerical
change effected by the bound command (same mechanism as precise scrolling).
Useful for the client API: key events can be sent to libmpv to handle
internally.
``keydown <name>``
Similar to ``keypress``, but sets the ``KEYDOWN`` flag so that if the key is

View File

@ -6197,7 +6197,8 @@ static void cmd_key(void *p)
cmd->success = false;
return;
}
mp_input_put_key_artificial(mpctx->input, code | action, 1);
double scale = action == 0 ? cmd->args[1].v.d : 1;
mp_input_put_key_artificial(mpctx->input, code | action, scale);
}
}
@ -6753,7 +6754,8 @@ const struct mp_cmd_def mp_cmds[] = {
.flags = MP_CMD_OPT_ARG}}},
{ "keybind", cmd_key_bind, { {"name", OPT_STRING(v.s)},
{"cmd", OPT_STRING(v.s)} }},
{ "keypress", cmd_key, { {"name", OPT_STRING(v.s)} },
{ "keypress", cmd_key, { {"name", OPT_STRING(v.s)},
{"scale", OPT_DOUBLE(v.d), OPTDEF_DOUBLE(1)} },
.priv = &(const int){0}},
{ "keydown", cmd_key, { {"name", OPT_STRING(v.s)} },
.priv = &(const int){MP_KEY_STATE_DOWN}},