Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to execute adb commands as fast as your code ? [SIMILAR TO #231] #1625

Open
rxydenxd opened this issue Jul 27, 2020 · 5 comments
Open

How to execute adb commands as fast as your code ? [SIMILAR TO #231] #1625

rxydenxd opened this issue Jul 27, 2020 · 5 comments

Comments

@rxydenxd
Copy link

[ SIMILAR TO #231 ]

I made a program which executes adb touchscreen commands according to my cursor position. As mentioned in #231 the adb commands are very slow. How can i use YOUR server to execute my commands?

@Helaer
Copy link

Helaer commented Jul 27, 2020

I also need to implement this feature, which is what I am looking forward to.

@rom1v
Copy link
Collaborator

rom1v commented Jul 27, 2020

#129 #613 #1016 #1249

@rxydenxd
Copy link
Author

adb push scrcpy-server.jar /data/local/tmp/scrcpy-server.jar
adb forward tcp:8080 localabstract:scrcpy
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 800000 true - true true

used these three commands but got stuck after the last command. There's no response until I CTRL+C

@rom1v
Copy link
Collaborator

rom1v commented Jul 28, 2020

That's expected, it gives control back once the server is terminated.

So you must execute this command in a separate process, then connect to localhost on port 8080 (according to your adb forward command) twice (once for the video socket, once for the control socket).

@rxydenxd
Copy link
Author

rxydenxd commented Jul 28, 2020

### UPDATE:
I put these commands in cmd:

1st CMD:
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 800000 true - true true
RESULT:same Ctrl+C thing, blocked cmd

2nd CMD:
adb forward tcp:8080 localabstract:scrcpy

after this I run my python script it gives an error, then in the 1st CMD this gets displayed:
WARN: Unknown event type: 48

PYTHON ERROR:

Traceback (most recent call last):
  File "C:\Users\rxydenxd\Desktop\adb.py", line 4, in <module>
    devices=adb.devices()
  File "C:\Python38\lib\site-packages\ppadb\command\host\__init__.py", line 23, in devices
    result = self._execute_cmd(cmd)
  File "C:\Python38\lib\site-packages\ppadb\command\host\__init__.py", line 14, in _execute_cmd
    conn.send(cmd)
  File "C:\Python38\lib\site-packages\ppadb\connection.py", line 77, in send
    return self._check_status()
  File "C:\Python38\lib\site-packages\ppadb\connection.py", line 80, in _check_status
    recv = self._recv(4).decode('utf-8')
  File "C:\Python38\lib\site-packages\ppadb\connection.py", line 56, in _recv
    return self.socket.recv(length)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

MY PYTHON SCRIPT:

from ppadb.client import Client

adb=Client(host='127.0.0.1',port=8080)
devices=adb.devices()
device=devices[0]


import pynput.keyboard
from pynput.mouse import Button,Controller,Listener
mouse = Controller()
mouse.position = (1300,350)     #home mouse x=1300 and y=350
#right thumb home position 350 1670

def on_move(x, y):
    mouseX=x-1300
    mouseY=y-350
    print(mouseX,mouseY)
    device.shell('input touchscreen swipe 350 1670 {toMoveX} {toMoveY} 10'.format(toMoveX=350+mouseX,toMoveY=1670+mouseY))
def on_press(key):
    print(key," pressed")
def on_release(key):
    print(key," released")
def on_click(x, y, button, pressed):
    print('{0} at {1}'.format(
        'Pressed' if pressed else 'Released',
        (x, y)))

# Collect events until released
with pynput.keyboard.Listener(on_release=on_release,on_press=on_press) as k_listener, \
        pynput.mouse.Listener(on_click=on_click,on_move=on_move) as m_listener:
    k_listener.join()
    m_listener.join()

When I use 5037 as port in line : adb=Client(host='127.0.0.1',port=8080) it executes perfectly, but with the 1 second delay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants