Controlling android ADB with AHK?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Controlling android ADB with AHK?

Post by kauan014 » 12 Aug 2021, 21:55

This works:

Code: Select all

cmd= C:/Android/platform-tools/adb.exe connect 127.0.0.1:7544 
ComOBJ := ComObjCreate("WScript.Shell").Exec(cmd)

Response := ComOBJ.StdOut.ReadAll()
MsgBox %Response%


But when i run the adb in shell:

Code: Select all

cmd= C:/Android/platform-tools/adb.exe -s 127.0.0.1:7544 shell
ComOBJ := ComObjCreate("WScript.Shell").Exec(cmd)

ComOBJ.StdIn.WriteLine("sendevent /dev/input/event0 1 67 1 sendevent /dev/input/event0 0 0 0")

Response := ComOBJ.StdOut.ReadAll()
MsgBox %Response%

It stuck in the StdOut.ReadAll() line forever, however, the command in StdIn.WriteLine is sent correctly.
The StdOut isnt a must, i added it just to try to 'force' the code await the command in WriteLine be executed/finished.


My goal is to keep just one adb running and continuously sent command to it:

Code: Select all

static COMOBJ

; Using shell here to avoid creating a new adb.exe instance for each command, and keep just the same one running.
if (COMOBJ = "") {	
   cmd= C:/Android/platform-tools/adb.exe -s 127.0.0.1:7544 shell
   ComOBJ := ComObjCreate("WScript.Shell").Exec(cmd)
}

ComOBJ.StdIn.WriteLine("sendevent /dev/input/event0 1 67 1 && sendevent /dev/input/event0 0 0 0")
Response := ComOBJ.StdOut.ReadAll() ; Currently code stuck in this line

If the code did not wait till the command sent on StdIn.WriteLine be executed/finished, it became completely async.
For example in a loop it sends new commands while the adb did not finished the previous one yet.

Im trying to avoid creating a new process for each command sent, would like to ask if someone know how to wait for a command sent by StdIn.WriteLine finish.

kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Re: Controlling android ADB with AHK?

Post by kauan014 » 14 Aug 2021, 16:06

Bump

Post Reply

Return to “Ask for Help (v1)”