summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortorque <torque@1>2015-06-10 16:56:56 -0700
committerwm4 <wm4@nowhere>2015-06-11 21:42:09 +0200
commitd0fe5e08b984db840545c1b341a1e56fad304593 (patch)
tree67b8ad9092b82bcd7dff3d77c0b30c144c93944d
parentb655ed5ed0c6d58a7e8937c28a7b2a0ccdf9c97e (diff)
downloadmpv-d0fe5e08b984db840545c1b341a1e56fad304593.tar.bz2
mpv-d0fe5e08b984db840545c1b341a1e56fad304593.tar.xz
command: add keypress, keydown, and keyup commands.
These commands are used to simulate keypresses using the key names from input.conf.
-rw-r--r--DOCS/interface-changes.rst1
-rw-r--r--DOCS/man/input.rst17
-rw-r--r--input/cmd_list.c3
-rw-r--r--input/cmd_list.h3
-rw-r--r--player/command.c30
5 files changed, 54 insertions, 0 deletions
diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst
index b6a77b6bd5..b7e693edd7 100644
--- a/DOCS/interface-changes.rst
+++ b/DOCS/interface-changes.rst
@@ -20,6 +20,7 @@ Interface changes
::
--- mpv 0.10.0 will be released ---
+ - add "keypress", "keydown", and "keyup" commands
- deprecate --ad-spdif-dtshd and enabling passthrough via --ad
add --audio-spdif as replacement
- remove "get_property" command
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index fb80007eb9..397e425c1e 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -395,6 +395,23 @@ List of Input Commands
<double>
The mouse event represents double-click.
+``keypress <key_name>``
+ Send a key event through mpv's input handler, triggering whatever
+ behavior is configured to that key. ``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.
+
+``keydown <key_name>``
+ Similar to ``keypress``, but sets the ``KEYDOWN`` flag so that if the key is
+ bound to a repeatable command, it will be run repeatedly with mpv's key
+ repeat timing until the ``keyup`` command is called.
+
+``keyup [<key_name>]``
+ Set the ``KEYUP`` flag, stopping any repeated behavior that had been
+ triggered. ``key_name`` is optional. If ``key_name`` is not given or is an
+ empty string, ``KEYUP`` will be set on all keys. Otherwise, ``KEYUP`` will
+ only be set on the key specified by ``key_name``.
+
``audio-add "<file>" [<flags> [<title> [<lang>]]]``
Load the given audio file. See ``sub-add`` command.
diff --git a/input/cmd_list.c b/input/cmd_list.c
index ec6b6f936a..c5249eb6f4 100644
--- a/input/cmd_list.c
+++ b/input/cmd_list.c
@@ -203,6 +203,9 @@ const struct mp_cmd_def mp_cmds[] = {
OARG_CHOICE(0, ({"single", 0},
{"double", 1})),
}},
+ { MP_CMD_KEYPRESS, "keypress", { ARG_STRING } },
+ { MP_CMD_KEYDOWN, "keydown", { ARG_STRING } },
+ { MP_CMD_KEYUP, "keyup", { OARG_STRING("") } },
{ MP_CMD_AUDIO_ADD, "audio-add", { ARG_STRING,
OARG_CHOICE(0, ({"select", 0}, {"auto", 1}, {"cached", 2})),
diff --git a/input/cmd_list.h b/input/cmd_list.h
index fad635f0b2..5870ff584b 100644
--- a/input/cmd_list.h
+++ b/input/cmd_list.h
@@ -87,6 +87,9 @@ enum mp_command_type {
MP_CMD_DROP_BUFFERS,
MP_CMD_MOUSE,
+ MP_CMD_KEYPRESS,
+ MP_CMD_KEYDOWN,
+ MP_CMD_KEYUP,
/// Audio Filter commands
MP_CMD_AF,
diff --git a/player/command.c b/player/command.c
index 7adb72902d..438879c228 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4846,6 +4846,36 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
break;
}
+ case MP_CMD_KEYPRESS:
+ case MP_CMD_KEYDOWN: {
+ const char *key_name = cmd->args[0].v.s;
+ int code = mp_input_get_key_from_name(key_name);
+ if (code < 0) {
+ MP_ERR(mpctx, "%s is not a valid input name.\n", key_name);
+ return -1;
+ }
+ if (cmd->id == MP_CMD_KEYDOWN)
+ code |= MP_KEY_STATE_DOWN;
+
+ mp_input_put_key(mpctx->input, code);
+ break;
+ }
+
+ case MP_CMD_KEYUP: {
+ const char *key_name = cmd->args[0].v.s;
+ if (key_name[0] == '\0') {
+ mp_input_put_key(mpctx->input, MP_INPUT_RELEASE_ALL);
+ } else {
+ int code = mp_input_get_key_from_name(key_name);
+ if (code < 0) {
+ MP_ERR(mpctx, "%s is not a valid input name.\n", key_name);
+ return -1;
+ }
+ mp_input_put_key(mpctx->input, code | MP_KEY_STATE_UP);
+ }
+ break;
+ }
+
default:
MP_VERBOSE(mpctx, "Received unknown cmd %s\n", cmd->name);
return -1;