' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Public Class Recorder

    Dim ProcID As Integer

    Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
        If m.Msg = &H100 Then  'WM_KEYDOWN
            Dim key As Keys = m.WParam
            If key = Keys.S And My.Computer.Keyboard.CtrlKeyDown Then
                Button2_Click(Nothing, Nothing)
                Return True
            End If
        End If
        Return MyBase.ProcessKeyPreview(m)
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        System.Threading.Thread.Sleep(2000)
        Me.WindowState = FormWindowState.Minimized
        If My.Computer.FileSystem.FileExists("D:\FFMPEG\bin\output.mp4") Then
            My.Computer.FileSystem.DeleteFile("D:\FFMPEG\bin\output.mp4") ', FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        ProcID = Shell("D:\FFMPEG\bin\ffmpeg.exe -f gdigrab -framerate 30 -i desktop D:\FFMPEG\bin\output.mp4", AppWinStyle.MaximizedFocus) ' AppWinStyle.MinimizedFocus)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        AppActivate(ProcID)
        My.Computer.Keyboard.SendKeys("q", True)
    End Sub

End Class