2013-12-26 16:10:35 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
2017-06-20 17:58:29 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-12-26 16:10:35 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-06-20 17:58:29 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-12-26 16:10:35 +00:00
|
|
|
*
|
2017-06-20 17:58:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-26 16:10:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
2014-07-10 06:28:03 +00:00
|
|
|
#include <strings.h>
|
2013-12-26 16:10:35 +00:00
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2013-12-26 16:10:35 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
|
|
|
|
#include "keycodes.h"
|
|
|
|
|
|
|
|
struct key_name {
|
|
|
|
int key;
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The names of the keys as used in input.conf
|
|
|
|
/// If you add some new keys, you also need to add them here
|
|
|
|
|
|
|
|
static const struct key_name key_names[] = {
|
|
|
|
{ ' ', "SPACE" },
|
|
|
|
{ '#', "SHARP" },
|
2015-10-21 20:25:30 +00:00
|
|
|
{ 0x3000, "IDEOGRAPHIC_SPACE" },
|
2013-12-26 16:10:35 +00:00
|
|
|
{ MP_KEY_ENTER, "ENTER" },
|
|
|
|
{ MP_KEY_TAB, "TAB" },
|
|
|
|
{ MP_KEY_BACKSPACE, "BS" },
|
|
|
|
{ MP_KEY_DELETE, "DEL" },
|
|
|
|
{ MP_KEY_INSERT, "INS" },
|
|
|
|
{ MP_KEY_HOME, "HOME" },
|
|
|
|
{ MP_KEY_END, "END" },
|
|
|
|
{ MP_KEY_PAGE_UP, "PGUP" },
|
|
|
|
{ MP_KEY_PAGE_DOWN, "PGDWN" },
|
|
|
|
{ MP_KEY_ESC, "ESC" },
|
|
|
|
{ MP_KEY_PRINT, "PRINT" },
|
|
|
|
{ MP_KEY_RIGHT, "RIGHT" },
|
|
|
|
{ MP_KEY_LEFT, "LEFT" },
|
|
|
|
{ MP_KEY_DOWN, "DOWN" },
|
|
|
|
{ MP_KEY_UP, "UP" },
|
|
|
|
{ MP_KEY_F+1, "F1" },
|
|
|
|
{ MP_KEY_F+2, "F2" },
|
|
|
|
{ MP_KEY_F+3, "F3" },
|
|
|
|
{ MP_KEY_F+4, "F4" },
|
|
|
|
{ MP_KEY_F+5, "F5" },
|
|
|
|
{ MP_KEY_F+6, "F6" },
|
|
|
|
{ MP_KEY_F+7, "F7" },
|
|
|
|
{ MP_KEY_F+8, "F8" },
|
|
|
|
{ MP_KEY_F+9, "F9" },
|
|
|
|
{ MP_KEY_F+10, "F10" },
|
|
|
|
{ MP_KEY_F+11, "F11" },
|
|
|
|
{ MP_KEY_F+12, "F12" },
|
2022-09-02 09:27:22 +00:00
|
|
|
{ MP_KEY_F+13, "F13" },
|
|
|
|
{ MP_KEY_F+14, "F14" },
|
|
|
|
{ MP_KEY_F+15, "F15" },
|
|
|
|
{ MP_KEY_F+16, "F16" },
|
|
|
|
{ MP_KEY_F+17, "F17" },
|
|
|
|
{ MP_KEY_F+18, "F18" },
|
|
|
|
{ MP_KEY_F+19, "F19" },
|
|
|
|
{ MP_KEY_F+20, "F20" },
|
|
|
|
{ MP_KEY_F+21, "F21" },
|
|
|
|
{ MP_KEY_F+22, "F22" },
|
|
|
|
{ MP_KEY_F+23, "F23" },
|
|
|
|
{ MP_KEY_F+24, "F24" },
|
2013-12-26 16:10:35 +00:00
|
|
|
{ MP_KEY_KP0, "KP0" },
|
|
|
|
{ MP_KEY_KP1, "KP1" },
|
|
|
|
{ MP_KEY_KP2, "KP2" },
|
|
|
|
{ MP_KEY_KP3, "KP3" },
|
|
|
|
{ MP_KEY_KP4, "KP4" },
|
|
|
|
{ MP_KEY_KP5, "KP5" },
|
|
|
|
{ MP_KEY_KP6, "KP6" },
|
|
|
|
{ MP_KEY_KP7, "KP7" },
|
|
|
|
{ MP_KEY_KP8, "KP8" },
|
|
|
|
{ MP_KEY_KP9, "KP9" },
|
|
|
|
{ MP_KEY_KPDEL, "KP_DEL" },
|
|
|
|
{ MP_KEY_KPDEC, "KP_DEC" },
|
|
|
|
{ MP_KEY_KPINS, "KP_INS" },
|
2023-08-24 23:48:45 +00:00
|
|
|
{ MP_KEY_KPHOME, "KP_HOME" },
|
|
|
|
{ MP_KEY_KPEND, "KP_END" },
|
|
|
|
{ MP_KEY_KPPGUP, "KP_PGUP" },
|
|
|
|
{ MP_KEY_KPPGDOWN, "KP_PGDWN" },
|
|
|
|
{ MP_KEY_KPRIGHT, "KP_RIGHT" },
|
|
|
|
{ MP_KEY_KPLEFT, "KP_LEFT" },
|
|
|
|
{ MP_KEY_KPDOWN, "KP_DOWN" },
|
|
|
|
{ MP_KEY_KPUP, "KP_UP" },
|
2013-12-26 16:10:35 +00:00
|
|
|
{ MP_KEY_KPENTER, "KP_ENTER" },
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
{ MP_MBTN_LEFT, "MBTN_LEFT" },
|
|
|
|
{ MP_MBTN_MID, "MBTN_MID" },
|
|
|
|
{ MP_MBTN_RIGHT, "MBTN_RIGHT" },
|
|
|
|
{ MP_WHEEL_UP, "WHEEL_UP" },
|
|
|
|
{ MP_WHEEL_DOWN, "WHEEL_DOWN" },
|
|
|
|
{ MP_WHEEL_LEFT, "WHEEL_LEFT" },
|
|
|
|
{ MP_WHEEL_RIGHT, "WHEEL_RIGHT" },
|
|
|
|
{ MP_MBTN_BACK, "MBTN_BACK" },
|
|
|
|
{ MP_MBTN_FORWARD, "MBTN_FORWARD" },
|
|
|
|
{ MP_MBTN9, "MBTN9" },
|
|
|
|
{ MP_MBTN10, "MBTN10" },
|
|
|
|
{ MP_MBTN11, "MBTN11" },
|
|
|
|
{ MP_MBTN12, "MBTN12" },
|
|
|
|
{ MP_MBTN13, "MBTN13" },
|
|
|
|
{ MP_MBTN14, "MBTN14" },
|
|
|
|
{ MP_MBTN15, "MBTN15" },
|
|
|
|
{ MP_MBTN16, "MBTN16" },
|
|
|
|
{ MP_MBTN17, "MBTN17" },
|
|
|
|
{ MP_MBTN18, "MBTN18" },
|
|
|
|
{ MP_MBTN19, "MBTN19" },
|
|
|
|
{ MP_MBTN_LEFT_DBL, "MBTN_LEFT_DBL" },
|
|
|
|
{ MP_MBTN_MID_DBL, "MBTN_MID_DBL" },
|
|
|
|
{ MP_MBTN_RIGHT_DBL, "MBTN_RIGHT_DBL" },
|
2013-12-26 16:10:35 +00:00
|
|
|
|
2019-10-22 14:41:19 +00:00
|
|
|
{ MP_KEY_GAMEPAD_ACTION_DOWN, "GAMEPAD_ACTION_DOWN" },
|
|
|
|
{ MP_KEY_GAMEPAD_ACTION_RIGHT, "GAMEPAD_ACTION_RIGHT" },
|
|
|
|
{ MP_KEY_GAMEPAD_ACTION_LEFT, "GAMEPAD_ACTION_LEFT" },
|
|
|
|
{ MP_KEY_GAMEPAD_ACTION_UP, "GAMEPAD_ACTION_UP" },
|
|
|
|
{ MP_KEY_GAMEPAD_BACK, "GAMEPAD_BACK" },
|
|
|
|
{ MP_KEY_GAMEPAD_MENU, "GAMEPAD_MENU" },
|
|
|
|
{ MP_KEY_GAMEPAD_START, "GAMEPAD_START" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_SHOULDER, "GAMEPAD_LEFT_SHOULDER" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_SHOULDER, "GAMEPAD_RIGHT_SHOULDER" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_TRIGGER, "GAMEPAD_LEFT_TRIGGER" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_TRIGGER, "GAMEPAD_RIGHT_TRIGGER" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_STICK, "GAMEPAD_LEFT_STICK" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_STICK, "GAMEPAD_RIGHT_STICK" },
|
|
|
|
{ MP_KEY_GAMEPAD_DPAD_UP, "GAMEPAD_DPAD_UP" },
|
|
|
|
{ MP_KEY_GAMEPAD_DPAD_DOWN, "GAMEPAD_DPAD_DOWN" },
|
|
|
|
{ MP_KEY_GAMEPAD_DPAD_LEFT, "GAMEPAD_DPAD_LEFT" },
|
|
|
|
{ MP_KEY_GAMEPAD_DPAD_RIGHT, "GAMEPAD_DPAD_RIGHT" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_STICK_UP, "GAMEPAD_LEFT_STICK_UP" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_STICK_DOWN, "GAMEPAD_LEFT_STICK_DOWN" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_STICK_LEFT, "GAMEPAD_LEFT_STICK_LEFT" },
|
|
|
|
{ MP_KEY_GAMEPAD_LEFT_STICK_RIGHT, "GAMEPAD_LEFT_STICK_RIGHT" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_STICK_UP, "GAMEPAD_RIGHT_STICK_UP" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_STICK_DOWN, "GAMEPAD_RIGHT_STICK_DOWN" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_STICK_LEFT, "GAMEPAD_RIGHT_STICK_LEFT" },
|
|
|
|
{ MP_KEY_GAMEPAD_RIGHT_STICK_RIGHT, "GAMEPAD_RIGHT_STICK_RIGHT" },
|
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
{ MP_KEY_POWER, "POWER" },
|
|
|
|
{ MP_KEY_MENU, "MENU" },
|
|
|
|
{ MP_KEY_PLAY, "PLAY" },
|
|
|
|
{ MP_KEY_PAUSE, "PAUSE" },
|
|
|
|
{ MP_KEY_PLAYPAUSE, "PLAYPAUSE" },
|
|
|
|
{ MP_KEY_STOP, "STOP" },
|
|
|
|
{ MP_KEY_FORWARD, "FORWARD" },
|
|
|
|
{ MP_KEY_REWIND, "REWIND" },
|
|
|
|
{ MP_KEY_NEXT, "NEXT" },
|
|
|
|
{ MP_KEY_PREV, "PREV" },
|
|
|
|
{ MP_KEY_VOLUME_UP, "VOLUME_UP" },
|
|
|
|
{ MP_KEY_VOLUME_DOWN, "VOLUME_DOWN" },
|
|
|
|
{ MP_KEY_MUTE, "MUTE" },
|
|
|
|
{ MP_KEY_HOMEPAGE, "HOMEPAGE" },
|
|
|
|
{ MP_KEY_WWW, "WWW" },
|
|
|
|
{ MP_KEY_MAIL, "MAIL" },
|
|
|
|
{ MP_KEY_FAVORITES, "FAVORITES" },
|
|
|
|
{ MP_KEY_SEARCH, "SEARCH" },
|
|
|
|
{ MP_KEY_SLEEP, "SLEEP" },
|
2015-02-14 02:50:26 +00:00
|
|
|
{ MP_KEY_CANCEL, "CANCEL" },
|
2017-07-25 13:51:40 +00:00
|
|
|
{ MP_KEY_RECORD, "RECORD" },
|
|
|
|
{ MP_KEY_CHANNEL_UP, "CHANNEL_UP" },
|
|
|
|
{ MP_KEY_CHANNEL_DOWN,"CHANNEL_DOWN" },
|
2020-01-21 18:15:51 +00:00
|
|
|
{ MP_KEY_PLAYONLY, "PLAYONLY" },
|
|
|
|
{ MP_KEY_PAUSEONLY, "PAUSEONLY" },
|
2023-11-27 06:04:10 +00:00
|
|
|
{ MP_KEY_GO_BACK, "GO_BACK" },
|
|
|
|
{ MP_KEY_GO_FORWARD, "GO_FORWARD" },
|
2023-08-15 11:27:03 +00:00
|
|
|
{ MP_KEY_TOOLS, "TOOLS" },
|
|
|
|
{ MP_KEY_ZOOMIN, "ZOOMIN" },
|
|
|
|
{ MP_KEY_ZOOMOUT, "ZOOMOUT" },
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
// These are kept for backward compatibility
|
|
|
|
{ MP_KEY_PAUSE, "XF86_PAUSE" },
|
|
|
|
{ MP_KEY_STOP, "XF86_STOP" },
|
|
|
|
{ MP_KEY_PREV, "XF86_PREV" },
|
|
|
|
{ MP_KEY_NEXT, "XF86_NEXT" },
|
|
|
|
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
// Deprecated numeric aliases for the mouse buttons
|
|
|
|
{ MP_MBTN_LEFT, "MOUSE_BTN0" },
|
|
|
|
{ MP_MBTN_MID, "MOUSE_BTN1" },
|
|
|
|
{ MP_MBTN_RIGHT, "MOUSE_BTN2" },
|
|
|
|
{ MP_WHEEL_UP, "MOUSE_BTN3" },
|
|
|
|
{ MP_WHEEL_DOWN, "MOUSE_BTN4" },
|
|
|
|
{ MP_WHEEL_LEFT, "MOUSE_BTN5" },
|
|
|
|
{ MP_WHEEL_RIGHT, "MOUSE_BTN6" },
|
|
|
|
{ MP_MBTN_BACK, "MOUSE_BTN7" },
|
|
|
|
{ MP_MBTN_FORWARD, "MOUSE_BTN8" },
|
|
|
|
{ MP_MBTN9, "MOUSE_BTN9" },
|
|
|
|
{ MP_MBTN10, "MOUSE_BTN10" },
|
|
|
|
{ MP_MBTN11, "MOUSE_BTN11" },
|
|
|
|
{ MP_MBTN12, "MOUSE_BTN12" },
|
|
|
|
{ MP_MBTN13, "MOUSE_BTN13" },
|
|
|
|
{ MP_MBTN14, "MOUSE_BTN14" },
|
|
|
|
{ MP_MBTN15, "MOUSE_BTN15" },
|
|
|
|
{ MP_MBTN16, "MOUSE_BTN16" },
|
|
|
|
{ MP_MBTN17, "MOUSE_BTN17" },
|
|
|
|
{ MP_MBTN18, "MOUSE_BTN18" },
|
|
|
|
{ MP_MBTN19, "MOUSE_BTN19" },
|
|
|
|
{ MP_MBTN_LEFT_DBL, "MOUSE_BTN0_DBL" },
|
|
|
|
{ MP_MBTN_MID_DBL, "MOUSE_BTN1_DBL" },
|
|
|
|
{ MP_MBTN_RIGHT_DBL, "MOUSE_BTN2_DBL" },
|
2017-09-02 14:00:52 +00:00
|
|
|
{ MP_WHEEL_UP, "AXIS_UP" },
|
|
|
|
{ MP_WHEEL_DOWN, "AXIS_DOWN" },
|
|
|
|
{ MP_WHEEL_LEFT, "AXIS_LEFT" },
|
|
|
|
{ MP_WHEEL_RIGHT, "AXIS_RIGHT" },
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
{ MP_KEY_CLOSE_WIN, "CLOSE_WIN" },
|
|
|
|
{ MP_KEY_MOUSE_MOVE, "MOUSE_MOVE" },
|
|
|
|
{ MP_KEY_MOUSE_LEAVE, "MOUSE_LEAVE" },
|
2015-02-17 05:50:57 +00:00
|
|
|
{ MP_KEY_MOUSE_ENTER, "MOUSE_ENTER" },
|
2013-12-26 16:10:35 +00:00
|
|
|
|
2015-12-23 18:13:45 +00:00
|
|
|
{ MP_KEY_UNMAPPED, "UNMAPPED" },
|
2019-11-21 21:22:45 +00:00
|
|
|
{ MP_KEY_ANY_UNICODE, "ANY_UNICODE" },
|
2015-12-23 18:13:45 +00:00
|
|
|
|
2013-12-26 16:10:35 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct key_name modifier_names[] = {
|
|
|
|
{ MP_KEY_MODIFIER_SHIFT, "Shift" },
|
|
|
|
{ MP_KEY_MODIFIER_CTRL, "Ctrl" },
|
|
|
|
{ MP_KEY_MODIFIER_ALT, "Alt" },
|
|
|
|
{ MP_KEY_MODIFIER_META, "Meta" },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int mp_input_get_key_from_name(const char *name)
|
|
|
|
{
|
|
|
|
int modifiers = 0;
|
|
|
|
const char *p;
|
|
|
|
while ((p = strchr(name, '+'))) {
|
|
|
|
for (const struct key_name *m = modifier_names; m->name; m++)
|
|
|
|
if (!bstrcasecmp(bstr0(m->name),
|
|
|
|
(struct bstr){(char *)name, p - name})) {
|
|
|
|
modifiers |= m->key;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
if (!strcmp(name, "+"))
|
|
|
|
return '+' + modifiers;
|
|
|
|
return -1;
|
|
|
|
found:
|
|
|
|
name = p + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bstr bname = bstr0(name);
|
|
|
|
|
|
|
|
struct bstr rest;
|
|
|
|
int code = bstr_decode_utf8(bname, &rest);
|
|
|
|
if (code >= 0 && rest.len == 0)
|
2014-08-26 18:39:28 +00:00
|
|
|
return mp_normalize_keycode(code + modifiers);
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
if (bstr_startswith0(bname, "0x"))
|
2014-08-26 18:39:28 +00:00
|
|
|
return mp_normalize_keycode(strtol(name, NULL, 16) + modifiers);
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
for (int i = 0; key_names[i].name != NULL; i++) {
|
|
|
|
if (strcasecmp(key_names[i].name, name) == 0)
|
2014-08-26 18:39:28 +00:00
|
|
|
return mp_normalize_keycode(key_names[i].key + modifiers);
|
2013-12-26 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-30 21:44:56 +00:00
|
|
|
static void mp_input_append_key_name(bstr *buf, int key)
|
2013-12-26 16:10:35 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; modifier_names[i].name; i++) {
|
|
|
|
if (modifier_names[i].key & key) {
|
2013-12-30 21:44:56 +00:00
|
|
|
bstr_xappend_asprintf(NULL, buf, "%s+", modifier_names[i].name);
|
2013-12-26 16:10:35 +00:00
|
|
|
key -= modifier_names[i].key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; key_names[i].name != NULL; i++) {
|
2013-12-30 21:44:56 +00:00
|
|
|
if (key_names[i].key == key) {
|
|
|
|
bstr_xappend_asprintf(NULL, buf, "%s", key_names[i].name);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-26 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 21:22:45 +00:00
|
|
|
if (MP_KEY_IS_UNICODE(key)) {
|
2013-12-30 21:44:56 +00:00
|
|
|
mp_append_utf8_bstr(NULL, buf, key);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-26 16:10:35 +00:00
|
|
|
|
|
|
|
// Print the hex key code
|
2014-10-16 22:52:42 +00:00
|
|
|
bstr_xappend_asprintf(NULL, buf, "0x%x", key);
|
2013-12-30 21:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *mp_input_get_key_name(int key)
|
|
|
|
{
|
|
|
|
bstr dst = {0};
|
|
|
|
mp_input_append_key_name(&dst, key);
|
|
|
|
return dst.start;
|
2013-12-26 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 01:30:17 +00:00
|
|
|
char *mp_input_get_key_combo_name(const int *keys, int max)
|
2013-12-26 16:10:35 +00:00
|
|
|
{
|
2013-12-30 21:44:56 +00:00
|
|
|
bstr dst = {0};
|
2013-12-26 16:10:35 +00:00
|
|
|
while (max > 0) {
|
2013-12-30 21:44:56 +00:00
|
|
|
mp_input_append_key_name(&dst, *keys);
|
2013-12-26 16:10:35 +00:00
|
|
|
if (--max && *++keys)
|
2013-12-30 21:44:56 +00:00
|
|
|
bstr_xappend(NULL, &dst, bstr0("-"));
|
2013-12-26 16:10:35 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2013-12-30 21:44:56 +00:00
|
|
|
return dst.start;
|
2013-12-26 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mp_input_get_keys_from_string(char *name, int max_num_keys,
|
|
|
|
int *out_num_keys, int *keys)
|
|
|
|
{
|
|
|
|
char *end, *ptr;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
ptr = name;
|
|
|
|
n = 0;
|
2014-11-21 08:58:09 +00:00
|
|
|
for (end = strchr(ptr, '-'); ; end = strchr(ptr, '-')) {
|
2013-12-26 16:10:35 +00:00
|
|
|
if (end && end[1] != '\0') {
|
|
|
|
if (end[1] == '-')
|
|
|
|
end = &end[1];
|
|
|
|
end[0] = '\0';
|
|
|
|
}
|
|
|
|
keys[n] = mp_input_get_key_from_name(ptr);
|
|
|
|
if (keys[n] < 0)
|
|
|
|
return 0;
|
|
|
|
n++;
|
|
|
|
if (end && end[1] != '\0' && n < max_num_keys)
|
|
|
|
ptr = &end[1];
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*out_num_keys = n;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mp_print_key_list(struct mp_log *out)
|
|
|
|
{
|
|
|
|
mp_info(out, "\n");
|
|
|
|
for (int i = 0; key_names[i].name != NULL; i++)
|
|
|
|
mp_info(out, "%s\n", key_names[i].name);
|
|
|
|
}
|
2014-08-26 18:39:28 +00:00
|
|
|
|
2020-05-14 20:22:33 +00:00
|
|
|
char **mp_get_key_list(void)
|
|
|
|
{
|
|
|
|
char **list = NULL;
|
|
|
|
int num = 0;
|
|
|
|
for (int i = 0; key_names[i].name != NULL; i++)
|
|
|
|
MP_TARRAY_APPEND(NULL, list, num, talloc_strdup(NULL, key_names[i].name));
|
|
|
|
MP_TARRAY_APPEND(NULL, list, num, NULL);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-08-26 18:39:28 +00:00
|
|
|
int mp_normalize_keycode(int keycode)
|
|
|
|
{
|
|
|
|
if (keycode <= 0)
|
|
|
|
return keycode;
|
|
|
|
int code = keycode & ~MP_KEY_MODIFIER_MASK;
|
|
|
|
int mod = keycode & MP_KEY_MODIFIER_MASK;
|
|
|
|
/* On normal keyboards shift changes the character code of non-special
|
|
|
|
* keys, so don't count the modifier separately for those. In other words
|
|
|
|
* we want to have "a" and "A" instead of "a" and "Shift+A"; but a separate
|
|
|
|
* shift modifier is still kept for special keys like arrow keys. */
|
|
|
|
if (code >= 32 && code < MP_KEY_BASE) {
|
|
|
|
/* Still try to support ASCII case-modifications properly. For example,
|
|
|
|
* we want to change "Shift+a" to "A", not "a". Doing this for unicode
|
|
|
|
* in general would require huge lookup tables, or a libc with proper
|
|
|
|
* unicode support, so we don't do that. */
|
|
|
|
if (code >= 'a' && code <= 'z' && (mod & MP_KEY_MODIFIER_SHIFT))
|
|
|
|
code &= 0x5F;
|
|
|
|
mod &= ~MP_KEY_MODIFIER_SHIFT;
|
|
|
|
}
|
|
|
|
return code | mod;
|
|
|
|
}
|