summaryrefslogtreecommitdiffstats
path: root/player/command.c
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 /player/command.c
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.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c30
1 files changed, 30 insertions, 0 deletions
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;