Using VLC's hot keys via the command line

1

vlc --help lists, among other content, command line options like the following:

 Hot keys
      --global-key-toggle-fullscreen <string>
                                 Fullscreen
      --key-toggle-fullscreen <string>
                                 Fullscreen
      --global-key-leave-fullscreen <string>
                                 Leave fullscreen
      --key-leave-fullscreen <string>
                                 Leave fullscreen
      --global-key-play-pause <string>
                                 Play/Pause
      --key-play-pause <string>  Play/Pause

When I try to use them though, they don't work at all. I don't understand why do they have to take a <string> parameter as well.

So my scenario looks like this:

  • I run VLC either with a UI or in headless mode
  • I execute e.g. vlc --key-next foo (for triggering "next"), foo being a dummy parameter
  • VLC doesn't complain (unlike when you don't pass a string), but command has no effect

What's a working example of command-line-triggered VLC hot keys?

vemv

Posted 2013-04-06T18:26:17.980

Reputation: 640

Do you wanna bind them? Why you need this? If you want to bind them use global hotkeys https://wiki.videolan.org/How_to_set_global_hotkeys/

– TechLife – 2015-01-21T22:21:52.143

You can control a large amount of vlc via dbus: see more here https://stackoverflow.com/questions/14256193/linux-control-a-running-vlc-process-through-command-line#14256241

– Michael Meanswell – 2018-03-23T20:22:31.633

Answers

2

By using vlc --key-next foo you've assigned "Next" to a key named "Foo", which you probably don't have. ;)

The <string> is composed of modifier keys (Alt, Shift, Ctrl, Meta, Command) separated by a dash (-) and terminated by a key (*a...z, +, =, -, ',', +, <, >, `, /, ;, ', \, [, ], , Left, Right, Up, Down, Space, Enter, F1...F12, Home, End, Menu, Esc, Page Up, Page Down, Tab, Backspace, Mouse Wheel Up and Mouse Wheel Down).

So vlc --key-next alt-n will set Alt+n to go to the Next media file loaded.

Alternatively vlc --key-next "Page Down" will set Page Down.

More info here.

Ƭᴇcʜιᴇ007

Posted 2013-04-06T18:26:17.980

Reputation: 103 763

Strictly speaking, I believe this answers my question. However, could you please tell me how to trigger a command such as next, rather than bind the command to a key? – vemv – 2013-04-06T19:02:51.387

1As far as I know, there's no way to control the player like that (start, stop, pause, prev, next, etc.) via command-line arguments. – Ƭᴇcʜιᴇ007 – 2013-04-06T19:25:01.693

wiki.videolan.org/VLC-0-8-6_command-line_help It doesnt look like a way to control it live, just ways to start it up. Some of the scripting methods that people worked on, became obsolete in later versions. Talking to it with HTML? might stay longer, beings every thing is "web" these days :-) – Psycogeek – 2013-04-06T19:50:20.880

Ahhh too bad. Given that VLC can run in single-instance mode (see terdon's answer) it should be feasible to communicate with the underlying running process behind the singleton instance. One can add files to its queue, so I was expecting that one could send it other kind of messages as well. – vemv – 2013-04-06T20:22:53.617

1

What you are asking for is almost certainly impossible. Command line arguments are passed to a program at launch. Once it has loaded, any settings changed will be in effect but you cannot pass any more arguments.

When you run vlc --whatever it will attempt to launch another instance of vlc which will load with the option --whatever set. If you have "allow only one instance" set in your vlc preferences, this will have no effect and it will look like "vlc does not complain". You might be able to get this sort of behavior from the VideoLanServer but I have never used it and do not know. You will not get this from any "normal" program that is not running in some kind of server or listening mode.

enter image description here

A better question is why would you need this behavior? If you are displaying vlc output normally, you can just use the hotkeys normally as long as the vlc window has the mouse focus. Even if you don't and you are, for example, watching vlc in a terminal over an ssh connection to a headless server using its ASCII art output modes, the hotkeys work as long as the terminal with the ssh has focus. Are you trying to somehow script this behavior? Could this be an XY problem?

terdon

Posted 2013-04-06T18:26:17.980

Reputation: 45 216

Yes I am using a single instance of VLC. I expected sending messages such as "play/pause" to those instances to be possible, since one can add additional items to a running instance from the command line. – vemv – 2013-04-06T20:15:16.357

Yes but what's the point of sending a hotkey at launch time? Do you want it to start paused? I don't understand what your desired behavior is. Why don't you just hit space when the video window has the focus? – terdon – 2013-04-06T20:17:05.890

No I don't want to send a hotkey at startup time. I want to send a message to running/existing instances: "stop the file you're playing". – vemv – 2013-04-06T20:18:20.617

1I guess mine could be considered an XY question. I was attempting to build a music manager on top of VLC and sending messages sounded very tempting. Will look into a proper approach such as leveraging an API then. – vemv – 2013-04-06T20:19:14.340

If all you want is to pause/unpause a single vlc instance, you can do kill -STOP $(pgrep vlc) to pause and kill -CONT $(pgrep vlc) to unpause. – terdon – 2013-04-06T20:23:44.403

Unfortunately that isn't the case. Tnanks for the suggestions. – vemv – 2013-04-06T21:00:04.340