function showRecord($owner) { $form = New-Object System.Windows.Forms.Form $form.Owner = $owner $form.icon = $icon $form.Text = "Grabar" $form.Width = 445 $form.Height = 305 $form.AutoSize = $true $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterParent $form.Font = "Microsoft Sans Serif, 9.35" $form.FormBorderStyle = 'FixedDialog' # $kl_proc = runKeylogger $hidden = New-Object System.Windows.Forms.Button $hidden.Width = 0 $hidden.Height = 0 $form.Controls.Add($hidden) $label_audio = New-Object System.Windows.Forms.Label $label_audio.Text = "Audio:" $label_audio.AutoSize = $true $label_audio.Location = New-Object System.Drawing.Point(20, 23) $list_audio = New-Object System.Windows.Forms.ComboBox $list_audio.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList; $list_audio.Width = 333 $list_audio.Location = New-Object System.Drawing.Point(77, 20) $devs = $( $output = & ffmpeg -hide_banner -nostats -list_devices true -f dshow -i dummy ) 2>&1 foreach ($d in ($devs -split "\n")) { if ($d.StartsWith("[dshow") -and $d.EndsWith("(audio)")) { $list_audio.Items.add(($d -split "`"")[1]) } } $list_audio.Items.add("") $list_audio.SelectedIndex = 0 $form.Controls.Add($label_audio) $form.Controls.Add($list_audio) $label_image = New-Object System.Windows.Forms.Label $label_image.Text = "Imagen:" $label_image.AutoSize = $true $label_image.Location = New-Object System.Drawing.Point(20, 60) $list_image = New-Object System.Windows.Forms.ComboBox $list_image.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList; $list_image.Width = 333 $list_image.Location = New-Object System.Drawing.Point(77, 57) $list_image.Items.add("Pantalla") $list_image.Items.add("Ventana") $list_image.Items.add("Fondo") $list_image.Items.add("") $list_image.SelectedIndex = 0 $form.Controls.Add($label_image) $form.Controls.Add($list_image) $list_image.Add_SelectedIndexChanged({ hide_option_fixed hide_option_window hide_option_screen switch ($this.SelectedItem) { "Pantalla" { show_option_screen } "Ventana" { show_option_window } "Fondo" { show_option_fixed } } }) function hide_option_fixed { $label_bg.AutoSize = $false $label_bg.Width = 0 $text_bg.Width = 0 $btn_bg.Width = 0 } function show_option_fixed { $global:image = "fixed" $label_bg.AutoSize = $true $btn_bg.Width = 75 $text_bg.Width = 252 } function hide_option_window { $label_window.AutoSize = $false $label_window.Width = 0 $list_window.Width = 0 } function show_option_window { $global:image = "window" $label_window.AutoSize = $true $list_window.Width = 333 $list_window.Items.Clear() $windows = Get-Process | Where-Object { $_.MainWindowTitle -ne "" } | Select-Object MainWindowTitle foreach ($win in $windows) { $list_window.Items.add((($win -split "=")[1] -split "}")[0]) } $list_window.SelectedIndex = 0; } function hide_option_screen { $label_screen.AutoSize = $false $label_screen.Width = 0 $list_screen.Width = 0 } function show_option_screen { $global:image = "screen" $label_screen.AutoSize = $true $list_screen.Width = 333 $list_screen.Items.Clear() $list_screen.Items.add("Todos") $screens = [System.Windows.Forms.Screen]::AllScreens $i = 1 foreach ($scr in $screens) { $list_screen.Items.add("Monitor $i - $((((($scr -split "\r\n") -split "}")[0] -split "{")[1] -split ",") -join ", ")") $i++ } $list_screen.SelectedIndex = 0; } # $radio_group = New-Object System.Windows.Forms.GroupBox # $radio_group.Location = New-Object System.Drawing.Point(20, 55) # $radio_group.Width = 390 # $radio_group.Height = 62 # $radio_group.text = "Imagen" # $form.Controls.Add($radio_group) # $radio_none = New-Object System.Windows.Forms.RadioButton # $radio_none.Location = '15,27' # $radio_none.AutoSize = $true # $radio_none.Checked = $false # $radio_none.Text = "Ninguna" # $radio_none.Add_Click({ # hide_radio_fixed # hide_radio_window # hide_radio_screen # }) # $radio_screen = New-Object System.Windows.Forms.RadioButton # $radio_screen.Location = '95,27' # $radio_screen.AutoSize = $true # $radio_screen.Checked = $true # $radio_screen.Text = "Pantalla" # $radio_screen.Add_Click({ # hide_radio_fixed # hide_radio_window # show_radio_screen # }) # $radio_window = New-Object System.Windows.Forms.RadioButton # $radio_window.Location = '170,27' # $radio_window.AutoSize = $true # $radio_window.Checked = $false # $radio_window.Text = "Ventana" # $radio_window.Add_Click({ # hide_radio_fixed # hide_radio_screen # show_radio_window # }) # $radio_fixed = New-Object System.Windows.Forms.RadioButton # $radio_fixed.Location = '250,27' # $radio_fixed.AutoSize = $true # $radio_fixed.Checked = $false # $radio_fixed.Text = "Fondo" # $radio_fixed.Add_Click({ # hide_radio_window # hide_radio_screen # show_radio_fixed # }) # $radio_webcam = New-Object System.Windows.Forms.RadioButton # $radio_webcam.Location = '315,27' # $radio_webcam.AutoSize = $true # $radio_webcam.Checked = $false # $radio_webcam.Enabled = $false # $radio_webcam.Text = "Webcam" # $radio_group.Controls.AddRange(@($radio_none, $radio_screen, $radio_window, $radio_fixed, $radio_webcam)) $label_bg = New-Object System.Windows.Forms.Label $label_bg.Text = "Fondo:" $label_bg.Location = New-Object System.Drawing.Point(20, 98) $text_bg = New-Object System.Windows.Forms.TextBox $text_bg.Location = New-Object System.Drawing.Point(77, 95) $text_bg.add_DoubleClick({ $text_bg.SelectAll(); }) $btn_bg = New-Object System.Windows.Forms.Button $btn_bg.Text = "Examinar" $btn_bg.Height = 26 $btn_bg.Location = New-Object System.Drawing.Point(335, 93) $btn_bg.Add_Click({ $res = selectFile -path "$root\res" -formats "Imágenes (*.*)|*.*" if ($res -ne $null) { $text_bg.Text = $res } }) $form.Controls.Add($label_bg) $form.Controls.Add($text_bg) $form.Controls.Add($btn_bg) $label_window = New-Object System.Windows.Forms.Label $label_window.Text = "Ventana:" $label_window.Location = New-Object System.Drawing.Point(20, 98) $list_window = New-Object System.Windows.Forms.ComboBox $list_window.Width = 333 $list_window.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList; $list_window.Location = New-Object System.Drawing.Point(77, 95) $form.Controls.Add($label_window) $form.Controls.Add($list_window) $label_screen = New-Object System.Windows.Forms.Label $label_screen.Text = "Monitor:" $label_screen.Location = New-Object System.Drawing.Point(20, 98) $list_screen = New-Object System.Windows.Forms.ComboBox $list_screen.Width = 333 $list_screen.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList; $list_screen.Location = New-Object System.Drawing.Point(77, 95) $form.Controls.Add($label_screen) $form.Controls.Add($list_screen) hide_option_fixed hide_option_window show_option_screen $label_dest = New-Object System.Windows.Forms.Label $label_dest.Text = "Destino:" $label_dest.AutoSize = $true $label_dest.Location = New-Object System.Drawing.Point(20, 138) $text_dest = New-Object System.Windows.Forms.TextBox $text_dest.Text = $def_dest_dir $text_dest.Width = 253 $text_dest.Location = New-Object System.Drawing.Point(77, 135) $text_dest.add_DoubleClick({ $text_dest.SelectAll(); }) $btn_dest = New-Object System.Windows.Forms.Button $btn_dest.Text = "Examinar" $btn_dest.AutoSize = $true $btn_dest.Location = New-Object System.Drawing.Point(335, 133) $btn_dest.Add_Click({ $dest = selectFolder -path $def_dest_dir if ($dest) { $text_dest.Text = $dest } }) $form.Controls.Add($label_dest) $form.Controls.Add($text_dest) $form.Controls.Add($btn_dest) $label_name = New-Object System.Windows.Forms.Label $label_name.Text = "Nombre:" $label_name.AutoSize = $true $label_name.Location = New-Object System.Drawing.Point(20, 177) $text_name = New-Object System.Windows.Forms.TextBox $text_name.Text = "Grabacion - $(Get-Date -Format "yyyy-MM-dd HH.mm")" $text_name.Width = 331 $text_name.Location = New-Object System.Drawing.Point(77, 174) $text_name.add_TextChanged({ removeInvalidChars -textbox $text_name }) $text_name.add_DoubleClick({ $text_name.SelectAll(); }) $text_name.Add_KeyDown({ if ($_.KeyCode -eq "Enter") { $btn_rec.PerformClick() } }) $form.Controls.Add($label_name) $form.Controls.Add($text_name) function finish { $buttonTimer.Dispose() if ($null -ne $curr_process) { taskkill -pid $curr_process.Id $global:curr_process = $null } $btn_stop.Width = 0 $btn_stop.Height = 0 $btn_rec.Width = 150 $btn_rec.Height = 30 printLog } # El evento process.exited no funciona, por eso uso un timer para cambiar el boton # https://github.com/PowerShell/PowerShell/issues/8000#issuecomment-542412046 $buttonTimer = [System.Windows.Forms.Timer]::new() $buttonTimer.Interval = 1000 $buttonTimer.Add_Tick({ if ($null -ne $curr_process -and $curr_process.HasExited) { finish } }) $btn_rec = New-Object System.Windows.Forms.Button $btn_rec.Text = "Grabar" $btn_rec.Location = New-Object System.Drawing.Point(140, 220) $btn_rec.Width = 150 $btn_rec.Height = 30 $btn_rec.Add_Click({ try { $prevCode = startAlwaysOn record -image $image -mic $list_audio.SelectedItem -window $list_window.SelectedItem -bg $text_bg.Text -monitor $list_screen.SelectedItem -out "$($text_dest.Text)\$($text_name.Text)" } finally { endAlwaysOn -code $prevCode } if ($null -ne $curr_process) { $btn_stop.Width = 150 $btn_stop.Height = 30 $btn_rec.Width = 0 $btn_rec.Height = 0 $buttonTimer.Start() } }) $btn_stop = New-Object System.Windows.Forms.Button $btn_stop.Text = "Detener" $btn_stop.Location = New-Object System.Drawing.Point(140, 220) $btn_stop.Width = 0 $btn_stop.Height = 0 $btn_stop.Add_Click({ finish }) $form.Controls.Add($btn_rec) $form.Controls.Add($btn_stop) $form.Add_Closing({ finish $owner.Location = getRelativeLocation -parent $owner -child $form $form.Hide() $owner.Show() }) [PSAppID]::SetAppIdForWindow($form.handle, "$($metadata.package).$app_name") $form.Add_LocationChanged({ $global:win_loc = $form.Location }) $form.Add_Resize({ $global:win_size = $form.Size }) $form.MaximizeBox = $false $form.ShowDialog() }