summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-23 19:13:45 +0100
committerwm4 <wm4@nowhere>2015-12-23 19:13:45 +0100
commitb0381d27eb19d8f70f4f711d41dd342c616ae843 (patch)
tree89eee7586c847ba69cd33d9d96be20ff3553646b
parent3e1aed8f40f0c35f78c74502050630519895c972 (diff)
downloadmpv-b0381d27eb19d8f70f4f711d41dd342c616ae843.tar.bz2
mpv-b0381d27eb19d8f70f4f711d41dd342c616ae843.tar.xz
input: add a catch-all "unmapped" command
This can be used to grab all unmapped keys. Fixes #2612.
-rw-r--r--DOCS/man/input.rst6
-rw-r--r--input/input.c4
-rw-r--r--input/keycodes.c2
-rw-r--r--input/keycodes.h3
4 files changed, 14 insertions, 1 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index e3fbddd778..cfe179c06f 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -546,6 +546,12 @@ Input Commands that are Possibly Subject to Change
Always bind a key. (The input section that was made active most recently
wins if there are ambiguities.)
+ This command can be used to dispatch arbitrary keys to a script or a client
+ API user. If the input section defines ``script-binding`` commands, it is
+ also possible to get separate events on key up/down, and relatively detailed
+ information about the key state. The special key name ``unmapped`` can be
+ used to match any unmapped key.
+
``overlay-add <id> <x> <y> "<file>" <offset> "<fmt>" <w> <h> <stride>``
Add an OSD overlay sourced from raw data. This might be useful for scripts
and applications controlling mpv, and which want to display things on top
diff --git a/input/input.c b/input/input.c
index 58907ccd50..24281fe99e 100644
--- a/input/input.c
+++ b/input/input.c
@@ -446,7 +446,9 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
return handle_test(ictx, code);
struct cmd_bind *cmd = find_any_bind_for_key(ictx, force_section, code);
- if (cmd == NULL) {
+ if (!cmd)
+ cmd = find_any_bind_for_key(ictx, force_section, MP_KEY_UNMAPPED);
+ if (!cmd) {
if (code == MP_KEY_CLOSE_WIN)
return mp_input_parse_cmd_strv(ictx->log, (const char*[]){"quit", 0});
int msgl = MSGL_WARN;
diff --git a/input/keycodes.c b/input/keycodes.c
index 21a3c10e64..d6c07288c2 100644
--- a/input/keycodes.c
+++ b/input/keycodes.c
@@ -171,6 +171,8 @@ static const struct key_name key_names[] = {
{ MP_KEY_MOUSE_LEAVE, "MOUSE_LEAVE" },
{ MP_KEY_MOUSE_ENTER, "MOUSE_ENTER" },
+ { MP_KEY_UNMAPPED, "UNMAPPED" },
+
{ 0, NULL }
};
diff --git a/input/keycodes.h b/input/keycodes.h
index d95edb1f45..da88d52c37 100644
--- a/input/keycodes.h
+++ b/input/keycodes.h
@@ -200,6 +200,9 @@
#define MP_KEY_IS_MOUSE(code) \
(MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_MOUSE_MOVE(code))
+// No input source should generate this.
+#define MP_KEY_UNMAPPED (MP_KEY_INTERN+4)
+
// Emit a command even on key-up (normally key-up is ignored). This means by
// default they binding will be triggered on key-up instead of key-down.
// This is a fixed part of the keycode, not a modifier than can change.