Conditionally send keystrokes

This is my first post and I am a complete beginner to this wonderful language.

I have 2 folders both containing MP4 files named like partn.mp4 where n is an integer.

I have a playlist file that contains the absolute path of each file like C:\Series\Show\part1.mp4, C:\Series\Adv\part2.mp4 and so on…

Series contains even numbered files (part1.mp4, part3.mp4,…), Adv contains odd ones.

Media player classic will play these files if given the playlist as an argument.

What I need is a way to send a Ctrl-4 to odd numbered ones, I only limited myself to 3 parts for simplicity, so I need to send the keystroke to part2.mp4

This code sends the keystroke to all files.

Other codes that I’ve tried create race conditions and only the last file will play, any help.

I am not attached to creating a playlist, any solution is fine.

mpc-hc.exe playlist.m3u /play
[void][System.reflection.assembly]::loadwithpartialname('system.Windows.forms')
Foreach ($line in get-content playlist.m3u) {
If ($line.substring($line.length-5,1) -match 2) {
 [System.Windows.forms.Sendkeys]::sendwait("^4")
  }
}

I don’t know why you are doing this, but…

You can

if((($line -split 'part')[-1] -replace '.mp4') % 2){
# Send key here
}

Let me explain, it is an assignment where the general idea is to insert commercials in a movie in order to fight piracy, this implementation proposes to split the movie into parts (odd numbered ones) and put it in a folder and advertisers in another one (even numbered), so to play them you must play one from each folder while having info about the commercial being played (the Ctrl-4).

I am open to suggestions.

I came with an idea of getting the entire movie, and trigger the commercial every 10 minutes while hiding the player’s window, but I am finding it too difficult for a beginner.

Anyway thanks, I’ll try the code and get back.