Search code examples
excelvbaadbctrl

vba excel macro to use adb


i'm trying to create a macro that allows me to take screenshot, video and retrieve them via adb. using shell + line i can do almost everything, but i cannot stop recording. the stop recording command is ctrl+c, but sending it via sendkeys is not working.

Private Sub CommandButton2_Click()
    If ComboBox1.Value = "data, ora e titolo" Then
        nomevideo = Format(Now, "dd-mm-yy_hh-mm-ss_") & "_" & TextBox2.Value & ".mp4"
    ElseIf ComboBox1.Value = "data e titolo" Then
        nomevideo = Format(Now, "dd-mm-yy_") & TextBox2.Value & ".mp4"
    Else
        nomevideo = Format(Now, "dd-mm-yy_hh-mm-ss") & ".mp4"
    End If
    video = "adb shell screenrecord /sdcard/" & nomevideo
    Debug.Print video & "registra video"
    Shell video
    CommandButton13.Visible = True
End Sub

Private Sub CommandButton5_Click()
    SendKeys "^c"
    Debug.Print "stop video"
End Sub

Solution

  • You need to activate the window of adb using AppActivate prior to sending control-c. See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/appactivate-statement for details.

    Ok, keep the window open when using shell: keep Shell / cmd open when launching R script from VBA