Skip to content

Commit 6aaca3e

Browse files
stable version
1 parent 7c9e222 commit 6aaca3e

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

Projects/TkinterGUI/ScrCpy_GUI.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
import os, json
3+
import threading
4+
from tkinter import *
5+
6+
ip = input('''
7+
----------------------------------------
8+
Press `CTRL + PAUSE/BREAK` keys to exit.
9+
10+
Press ENTER for default IP
11+
192.168.0.103
12+
----------------------------------------
13+
14+
Paste IP Address of Device : ''')
15+
16+
17+
def task1():
18+
global ip
19+
print()
20+
21+
print("Task 1 assigned to thread: {}".format(threading.current_thread().name))
22+
print("ID of process running task 1: {}".format(os.getpid()))
23+
24+
if ip == '':
25+
ip = '192.168.0.103'
26+
27+
while True:
28+
print()
29+
os.system(f'scrcpy --tcpip={ip}')
30+
31+
32+
def task2():
33+
print()
34+
35+
print("Task 2 assigned to thread: {}".format(threading.current_thread().name))
36+
print("ID of process running task 2: {}".format(os.getpid()))
37+
38+
def power():
39+
os.system(f'adb -s {ip} shell input keyevent 26')
40+
41+
def volup():
42+
os.system(f'adb -s {ip} shell input keyevent 24')
43+
44+
def voldown():
45+
os.system(f'adb -s {ip} shell input keyevent 25')
46+
47+
def fun():
48+
key = num_list.get(num_list.curselection()[0])
49+
key = key.split(' : ')[0]
50+
os.system(f'adb -s {ip} shell input keyevent {key}')
51+
52+
while True:
53+
root = Tk()
54+
root.geometry("300x600")
55+
root.title("ScrCpy GUI")
56+
root.config(bg="gray")
57+
58+
num_list = Listbox(root, height=15, width=30)
59+
with open('keyevents.json') as f:
60+
data = json.load(f)
61+
62+
for i in data['key_events']:
63+
j = data['key_events'][i]
64+
k = j.split('adb shell input keyevent ')
65+
num_list.insert(k[1], f'{k[1]} : {i.split("key_")[1]}')
66+
67+
num_list.place(relx=0.5, rely=0.4, anchor='center')
68+
get_num_btn = Button(root, bg='green', text="Run ADB", command=fun)
69+
get_num_btn.place(relx=0.5, rely=0.1, anchor='center')
70+
71+
VolumeUp = Button(root, text="Volume Up", command=volup)
72+
VolumeUp.place(relx=0.5, rely=0.7, anchor='center')
73+
74+
VolumeDown = Button(root, text="Volume Down", command=voldown)
75+
VolumeDown.place(relx=0.5, rely=0.8, anchor='center')
76+
77+
Power = Button(root, bg='red', text="Power ON / OFF", command=power)
78+
Power.place(relx=0.5, rely=0.9, anchor='center')
79+
root.mainloop()
80+
81+
82+
if __name__ == "__main__":
83+
os.system('color 2')
84+
print()
85+
86+
print("ID of process running main program: {}".format(os.getpid()))
87+
print("Main thread name: {}".format(threading.current_thread().name))
88+
89+
t1 = threading.Thread(target=task1, name='t1')
90+
t2 = threading.Thread(target=task2, name='t2')
91+
92+
t1.start()
93+
t2.start()
94+
95+
t1.join()
96+
t2.join()

0 commit comments

Comments
 (0)