Using VLC's hot keys via the command line

11,423

Solution 1

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.

Solution 2

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?

Share:
11,423
deprecated
Author by

deprecated

Updated on September 18, 2022

Comments

  • deprecated
    deprecated over 1 year

    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?

  • deprecated
    deprecated about 11 years
    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?
  • Ƭᴇcʜιᴇ007
    Ƭᴇcʜιᴇ007 about 11 years
    As far as I know, there's no way to control the player like that (start, stop, pause, prev, next, etc.) via command-line arguments.
  • deprecated
    deprecated about 11 years
    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.
  • terdon
    terdon about 11 years
    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?
  • deprecated
    deprecated about 11 years
    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".
  • deprecated
    deprecated about 11 years
    I 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.
  • deprecated
    deprecated about 11 years
    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.
  • deprecated
    deprecated about 11 years
    Unfortunately that isn't the case. Tnanks for the suggestions.