[Python] ์•ˆ๋“œ๋กœ์ด๋“œ ๋งˆ์šฐ์Šคํƒญ ์ด๋ฒคํŠธ

2020. 6. 21. 16:43ยทLanguages/Python

ppadb์™€ pynput์„ ํ™œ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

๋””๋ฐ”์ด์Šค ํ‚ค๊ฐ’์€ adb devices๋ฅผ ํ†ตํ•ด ์–ป์–ด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

from ppadb.client import Client as AdbClient
from pynput.keyboard import Key, Listener
import time
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("ce0*******642702")
# device.shell("logcat", handler=dump_logcat)

isNotPressRight = True
isNotPressLeft = True
isNotPressUp = True
isNotPressDown = True
def excuteTouch(x, y):
    device.shell("sendevent /dev/input/event0 3 57 0 && sendevent /dev/input/event0 3 47 0 && sendevent /dev/input/event0 3 53 {0} && sendevent /dev/input/event0 3 54 {1} && sendevent /dev/input/event0 1 330 1 && sendevent /dev/input/event0 0 0 0".format(x, y))

def releaseTouch():
    device.shell("sendevent /dev/input/event0 3 57 4294967295 && sendevent /dev/input/event0 3 47 0 && sendevent /dev/input/event0 1 330 0 && sendevent /dev/input/event0 0 0 0")

def on_press(key):
# ํด๋ฆญ ์ขŒํ‘œ๋Š” ์ฃผ์„์„ ํ•ด์ œํ•˜๋ฉด ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
    # print('{0} pressed'.format(key))
    global isNotPressRight
    global isNotPressLeft
    global isNotPressUp
    global isNotPressDown
    if key == Key.right and isNotPressRight:
        isNotPressRight = False
        excuteTouch(3600, 700)
    elif key == Key.left and isNotPressLeft:
        isNotPressLeft = False
        excuteTouch(3600, 3400)
    elif key == Key.down and isNotPressDown:
        isNotPressDown = False
        excuteTouch(3700, 1100)
    elif key == Key.up and isNotPressUp:
        isNotPressUp = False
        excuteTouch(2600, 900)

def on_release(key):
    # print('{0} release'.format(key))
    global isNotPressRight
    global isNotPressLeft
    global isNotPressUp
    global isNotPressDown
    if key == Key.right:
        releaseTouch()
        isNotPressRight = True
    elif key == Key.left:
        releaseTouch()
        isNotPressLeft = True
    elif key == Key.down:
        releaseTouch()
        isNotPressDown = True
    elif key == Key.up:
        releaseTouch()
        isNotPressUp = True
        

    if key == Key.esc:
        # Stop listener
        return False

# Collect events until released
with Listener(
        on_press=on_press,
        on_release=on_release
) as listener: listener.join()
 

 

 

scrcpy๋กœ ํ™”๋ฉด์„ ์ถœ๋ ฅํ•˜๋ฉฐ python๋ฅผ ํ†ตํ•ด ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์„ ๋ฐ›์•„ adb ๋ช…๋ น์–ด๋ฅผ ์ „์†กํ•˜๋Š” ๊ฐ„๋‹จํ•œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

2020/06/21 - [Tool/scrcpy] - [scrcpy] scrcpy ๋ž€?

 

[scrcpy] scrcpy ๋ž€?

์•ˆ๋“œ๋กœ์ด๋“œ ๊ธฐ๊ธฐ๋ฅผ USB๋‚˜ over TCP/IP๋ฅผ ํ†ตํ•ด ์—ฐ๊ฒฐํ•˜๊ณ  ์ปดํ“จํ„ฐ์— ํ™”๋ฉด์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฃจํŠธ ๊ถŒํ•œ์ด ์—†์–ด๋„ ๋ฉ๋‹ˆ๋‹ค. GNU/Linux, Windows and macOS์—์„œ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. It focuses on: ๊ฐ€๋ฒผ์›€ (native, d..

codeparadise.tistory.com

 

 

728x90
'Languages/Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [Python] Tensorflow 2 ๊ฐœ๋ฐœํ™˜๊ฒฝ ์…‹ํŒ… on Windows 11
  • [Python] ๋…ผ๋ฆฌํšŒ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ
์ง€๋‹ˆ๐Ÿงž‍โ™‚๏ธ๐Ÿฅญ
์ง€๋‹ˆ๐Ÿงž‍โ™‚๏ธ๐Ÿฅญ
์ผ์ƒ, ๊ฒŒ์ž„, ๋ง›์ง‘, ์—ฌํ–‰, ๊ฐœ๋ฐœ, IT ๋ธ”๋กœ๊ทธ๐Ÿงž
  • ์ง€๋‹ˆ๐Ÿงž‍โ™‚๏ธ๐Ÿฅญ
    ์š”์ˆ  ๋žจํ”„๐Ÿซ–
    ์ง€๋‹ˆ๐Ÿงž‍โ™‚๏ธ๐Ÿฅญ
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • All (549)
      • Languages (57)
        • JAVA (13)
        • JSP (1)
        • C_C++ (4)
        • Html (3)
        • CSS (1)
        • JavaScript (18)
        • Python (3)
        • Kotlin (13)
        • TypeScript (1)
      • Framework (14)
        • spring (11)
        • jstl (1)
        • angular (2)
      • Tool (28)
        • Eclipse (5)
        • vsCode (3)
        • scrcpy (2)
        • Git (1)
        • IntelliJ (6)
        • Visual-studio (1)
        • UML (1)
        • Gradle (8)
      • DB (6)
        • Oracle (1)
        • MySql (3)
        • Mongo (2)
      • OS (14)
        • Linux (2)
        • Windows (12)
      • Server (8)
        • Tomcat (1)
        • Apache (1)
        • Node.js (6)
      • Programmings (25)
        • Design Pattern (2)
        • Funny (20)
        • Algorithms (3)
      • Cloud (8)
        • Docker (1)
        • Kubernetes (4)
        • Istio (1)
        • ArgoCD (2)
      • IT (5)
        • gRPC (3)
        • RESTful (3)
        • Web UI (5)
        • AI (4)
      • Book (6)
      • TIP (187)
      • Life (53)
      • Game (83)
      • Storage (22)
      • ์‹๋‹น (15)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ํ™ˆ
    • ํƒœ๊ทธ
    • ๋ฐฉ๋ช…๋ก
    • ์‚ฌ์ดํŠธ๋งต
    • RSS
    • ๊ธฐํƒ€ ์†Œ๋“
  • ๋งํฌ

    • ๊ตฌ๊ธ€
    • ๋„ค์ด๋ฒ„
    • ์ •๋ถ€24
    • Spring Framework ๋ฆด๋ฆฌ์ฆˆ ๋…ธํŠธ
    • Kotlin ๋ฆด๋ฆฌ์ฆˆ ๋…ธํŠธ
    • ์นด์นด์˜ค ์• ๋“œํ•
    • ๋ธ”๋กœ๊ทธ ์‚ฌ์ดํŠธ๋งต
    • ๋ธ”๋กœ๊ทธ RSS
  • ๊ณต์ง€์‚ฌํ•ญ

    • ์•ˆ๋…•ํ•˜์„ธ์š”
  • ์ธ๊ธฐ ๊ธ€

  • ํƒœ๊ทธ

    ์˜ค๋Š˜์˜๋‰ด์Šค
    ๋ฐ์ผ๋ฆฌ ๋‰ด์Šค
    ํ€˜์ŠคํŠธ
    ๋ธŒ๋ฆฌํ•‘
    ๋‰ด์Šค
    ํƒœ๊ตญ
    ํ•œ๋ˆˆ์— ๋ณด๋Š” ์˜ค๋Š˜์˜ ๋‰ด์Šค
    ๋ชฌ์Šคํ„ฐํ—Œํ„ฐ์™€์ผ์ฆˆ
    ๋ชฌ์Šคํ„ฐํ—Œํ„ฐ๋‚˜์šฐ
    ๋‰ด์Šค ๋ธŒ๋ฆฌํ•‘
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
์ง€๋‹ˆ๐Ÿงž‍โ™‚๏ธ๐Ÿฅญ
[Python] ์•ˆ๋“œ๋กœ์ด๋“œ ๋งˆ์šฐ์Šคํƒญ ์ด๋ฒคํŠธ
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”