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

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

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 ๋ธ”๋กœ๊ทธ๐Ÿป
  • ๊ณฐ๊ณฐ์ด๐Ÿงธ
    24K๐Ÿงˆ
    ๊ณฐ๊ณฐ์ด๐Ÿงธ
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • All (711)
      • 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)
      • Cloud (9)
        • Docker (1)
        • Kubernetes (5)
        • Istio (1)
        • ArgoCD (2)
      • Programmings (25)
        • Design Pattern (2)
        • Funny (20)
        • Algorithms (3)
      • IT (21)
        • gRPC (3)
        • RESTful (3)
        • Web UI (5)
        • AI (5)
      • ์‚ฌ์ฃผ (63)
        • ์ผ์ฃผ๋ก  (61)
        • ์œ ๋ช…์ธ (2)
      • Game (123)
        • ๋ชฌ์Šคํ„ฐํ—Œํ„ฐ (53)
        • ๋ถ‰์€์‚ฌ๋ง‰ (35)
      • ์‚ฌ์„œ์˜ค๊ฒฝ (46)
        • ๋Œ€ํ•™ (11)
        • ๋…ผ์–ด (35)
      • Book (6)
      • TIP (191)
        • ์‚ด๊นŒ๋ง๊นŒ (3)
      • Life (60)
      • Storage (22)
      • ์‹๋‹น (15)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

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

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

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

  • ํƒœ๊ทธ

    ์ผ์ฃผ๋ก 
    ๋…ผ์–ด
    ๋ถ‰์€์‚ฌ๋ง‰
    ์‚ฌ์ฃผ
    ์‚ฌ์„œ์‚ผ๊ฒฝ
    ํ•œ๋ˆˆ์— ๋ณด๋Š” ์˜ค๋Š˜์˜ ๋‰ด์Šค
    ๋‰ด์Šค ๋ธŒ๋ฆฌํ•‘
    ์‚ฌ์„œ์˜ค๊ฒฝ
    ๋‰ด์Šค
    ์˜ค๋Š˜์˜๋‰ด์Šค
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

๊ณฐ๊ณฐ์ด๐Ÿงธ
[Python] ์•ˆ๋“œ๋กœ์ด๋“œ ๋งˆ์šฐ์Šคํƒญ ์ด๋ฒคํŠธ
๋Œ“๊ธ€๋กœ ์ƒ๋‹จ์œผ๋กœ

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