LINUX.ORG.RU

MPV. Несколько горячих клавиш для одной команды

 ,


0

1

В скрипте, отображающем плейлист, когда подвязываешь на одну и ту же команду несколько клавиш, они в результате друг друга перезаписывают и работает только последнее назначение.

function add_keybinds()

  mp.add_forced_key_binding('k', 'moveup', moveup, "repeatable")
  mp.add_forced_key_binding('л', 'moveup', moveup, "repeatable")

end

Как привязать несколько клавиш для одной команды?

Контекст кода здесь: GitHub - playlist manager for mpv



Последнее исправление: Dreamdrawer (всего исправлений: 2)

Я пришёл сюда сообщить, что твой вопрос не про Lua, он про mpv.
Lua — встраиваемый скриптовый язык, названия функций и их поведение это специфика каждой конкретной программы. И у тебя как раз вопрос по программе, а не по самому языку. Если ты добавишь в теги mpv и изменишь заголовок и содержимое стартового поста так, чтобы сразу было понятно, что вопрос про mpv, у тебя будет намного больше шансов получить нужный ответ.

i-rinat ★★★★★
()

По идее, когда ты нажимаешь на кнопку, приложение получает информацию о событии, в котором есть «код» нажатой клавиши. Чтобы получить букву в текущей раскладке, нужно производить дополнительные действия, которые mpv и делает. Зачем-то.

Если совсем припрёт, можешь просто запатчить mpv, чтобы он так не делал:

diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index 25325e7..4ceb407 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -1065,29 +1065,13 @@ void vo_x11_check_events(struct vo *vo)
             }
             break;
         case KeyPress: {
-            char buf[100];
-            KeySym keySym = 0;
             int modifiers = get_mods(Event.xkey.state);
             if (x11->no_autorepeat)
                 modifiers |= MP_KEY_STATE_DOWN;
-            if (x11->xic) {
-                Status status;
-                int len = Xutf8LookupString(x11->xic, &Event.xkey, buf,
-                                            sizeof(buf), &keySym, &status);
-                int mpkey = vo_x11_lookupkey(keySym);
-                if (mpkey) {
-                    mp_input_put_key(x11->input_ctx, mpkey | modifiers);
-                } else if (status == XLookupChars || status == XLookupBoth) {
-                    struct bstr t = { buf, len };
-                    mp_input_put_key_utf8(x11->input_ctx, modifiers, t);
-                }
-            } else {
-                XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
-                              &x11->compose_status);
-                int mpkey = vo_x11_lookupkey(keySym);
-                if (mpkey)
-                    mp_input_put_key(x11->input_ctx, mpkey | modifiers);
-            }
+
+            KeySym keySym = XLookupKeysym(&Event.xkey, 0);
+            int mpkey = vo_x11_lookupkey(keySym);
+            mp_input_put_key(x11->input_ctx, mpkey | modifiers);
             break;
         }
         // Releasing all keys in these situations is simpler and ensures no

У тебя отвалятся комбинации с Shift и другими модификаторами. Наверняка это можно побороть, но я дальше не вникал. Патч работает только для mpv под иксами.

i-rinat ★★★★★
()

не это? https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst#id3

Example:

function something_handler()
    print("the key was pressed")
end
mp.add_key_binding("x", "something", something_handler)
This will print the message the key was pressed when x was pressed.

The user can remap these key bindings. Then the user has to put the following into their input.conf to remap the command to the y key:

y script-binding something
This will print the message when the key y is pressed. (x will still work, unless the user remaps it.)

You can also explicitly send a message to a named script only. Assume the above script was using the filename fooscript.lua:

y script-binding fooscript/something
anonymous
()
Ответ на: комментарий от anonymous

Либо я чего то не понял, либо это не так должно работать. В скрипте оно так и вписано:

function add_keybinds()
  mp.add_forced_key_binding('k', 'moveup', moveup, "repeatable")
  mp.add_forced_key_binding('j', 'movedown', movedown, "repeatable")

  mp.add_forced_key_binding('л', 'moveup', moveup, "repeatable")
  mp.add_forced_key_binding('о', 'movedown', movedown, "repeatable")
end

а если добавить к этому

function something_handler()
    print("the key was pressed")
end
mp.add_key_binding("k", "moveup", moveup, "repeatable")
mp.add_key_binding("j", "movedown", movedown, "repeatable")

то это никакого эффекта не производит.

Dreamdrawer
() автор топика
Ответ на: комментарий от Dreamdrawer

Ну типа обьявляешь одно значение а потом к нему дополнительное и смотреть что бы дальше не было переназначено по идеи убрать

This will print the message when the key y is pressed. (x will still work, unless the user remaps it.)

You can also explicitly send a message to a named script only. Assume the above script was using the filename fooscript.lua:

anonymous
()

Решение найдено

Необходимо дать разные названия функции (или это псевдоним функции, я не знаю как это правильно называется):

function add_keybinds()

  mp.add_forced_key_binding('k', 'moveup1', moveup)
  mp.add_forced_key_binding('л', 'moveup2', moveup)

end
Dreamdrawer
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.