0

I am using start-process to call vlc to play an audio file. I want to capture the keyboard input of this vlc process. Pressed keys should not be passed to vlc but to my calling program, such that I can check using $host.UI.RawUI.KeyAvailable or something similar. How can that be done?

function PlaySong {

    param ( [Parameter(Mandatory=$true)]
            $SongObject, 
            [Parameter(Mandatory=$false)]
            $CurrentSpeed = $SongObject.StartSpeed
          )

    $ArgList = " --play-and-exit" +
               " --quiet -I dummy" +
               " --audio-filter=scaletempo_pitch --pitch-shift " + $SongObject.PitchShift +
               " --start-time " + $SongObject.StartTime +
               " --stop-time " + $SongObject.EndTime +
               " --rate " + $CurrentSpeed +
               " --novideo" +
               " `"" + $SongObject.Path + "`""

    $prc = start-process -PassThru -FilePath vlc -ArgumentList $ArgList
    Wait-Process -Id $prc.Id -ErrorAction SilentlyContinue
}
jamacoe
  • 519
  • 4
  • 16

1 Answers1

0

I call this function PlaySong from a loop:

function LoopSong {
    while ($true) {
        PlaySong $d[$Nr] $CurrentSpeed
        if ($host.UI.RawUI.KeyAvailable) {
            $key = $host.UI.RawUI.ReadKey() 
            break 
        }
    }
   # ...
}

The vlc option -I dummy disables the GUI and all keyboard input while playing will be buffered and is available to ReadKey() after return.

jamacoe
  • 519
  • 4
  • 16