|
1 | 1 |
|
2 | | -import os |
| 2 | +import os, json |
3 | 3 | import threading |
4 | 4 | from tkinter import * |
5 | 5 |
|
@@ -53,30 +53,57 @@ def submit(x): |
53 | 53 | except Exception as e: |
54 | 54 | print(e) |
55 | 55 |
|
| 56 | + def fun(): |
| 57 | + key = num_list.get(num_list.curselection()[0]) |
| 58 | + key = key.split(' : ')[0] |
| 59 | + os.system(f'adb -s {ip} shell input keyevent {key}') |
| 60 | + |
56 | 61 | while True: |
57 | 62 | root = Tk() |
58 | | - |
59 | 63 | root.geometry("300x600") |
60 | 64 | root.title("ScrCpy GUI") |
61 | | - |
62 | 65 | root.config(bg="gray") |
63 | | - event = StringVar() |
64 | 66 |
|
65 | | - btn1 = Entry(root, textvariable = event) |
66 | | - btn1.insert(0, '209') # Open Music App |
67 | | - btn1.place(relx=0.5, rely=0.1, anchor='center') |
| 67 | + try: |
| 68 | + rely3 = 0.7 |
| 69 | + rely4 = 0.8 |
| 70 | + rely5 = 0.9 |
| 71 | + |
| 72 | + num_list = Listbox(root, height=15, width=30) |
| 73 | + with open('keyevents.json') as f: |
| 74 | + data = json.load(f) |
| 75 | + |
| 76 | + for i in data['key_events']: |
| 77 | + j = data['key_events'][i] |
| 78 | + k = j.split('adb shell input keyevent ') |
| 79 | + num_list.insert(k[1], f'{k[1]} : {i.split("key_")[1]}') |
| 80 | + |
| 81 | + num_list.place(relx=0.5, rely=0.4, anchor='center') |
| 82 | + get_num_btn = Button(root, bg='green', text="Run ADB", command=fun) |
| 83 | + get_num_btn.place(relx=0.5, rely=0.1, anchor='center') |
| 84 | + |
| 85 | + except: |
| 86 | + rely3 = 0.5 |
| 87 | + rely4 = 0.6 |
| 88 | + rely5 = 0.8 |
| 89 | + |
| 90 | + event = StringVar() |
| 91 | + btn1 = Entry(root, textvariable = event) |
| 92 | + |
| 93 | + btn1.insert(0, '209') # Open Music App |
| 94 | + btn1.place(relx=0.5, rely=0.1, anchor='center') |
68 | 95 |
|
69 | | - btn2 = Button(root, bg='green', text = 'Keyevent', command=lambda: submit(event.get())) |
70 | | - btn2.place(relx=0.5, rely=0.2, anchor='center') |
| 96 | + btn2 = Button(root, bg='green', text = 'Keyevent', command=lambda: submit(event.get())) |
| 97 | + btn2.place(relx=0.5, rely=0.2, anchor='center') |
71 | 98 |
|
72 | 99 | btn3 = Button(root, text="Volume Up", command=volup) |
73 | | - btn3.place(relx=0.5, rely=0.5, anchor='center') |
| 100 | + btn3.place(relx=0.5, rely=rely3, anchor='center') |
74 | 101 |
|
75 | 102 | btn4 = Button(root, text="Volume Down", command=voldown) |
76 | | - btn4.place(relx=0.5, rely=0.6, anchor='center') |
| 103 | + btn4.place(relx=0.5, rely=rely4, anchor='center') |
77 | 104 |
|
78 | 105 | btn5 = Button(root, bg='red', text="Power ON / OFF", command=power) |
79 | | - btn5.place(relx=0.5, rely=0.8, anchor='center') |
| 106 | + btn5.place(relx=0.5, rely=rely5, anchor='center') |
80 | 107 | root.mainloop() |
81 | 108 |
|
82 | 109 |
|
|
0 commit comments