-
Notifications
You must be signed in to change notification settings - Fork 1
/
yuumi-client.py
104 lines (85 loc) · 3.36 KB
/
yuumi-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys
import requests
import threading
from pynput import mouse, keyboard
import time
import configparser
running = True
# Load configuration
config = configparser.ConfigParser()
config.read('config.ini')
yuumi_pc_ip = config.get('General', 'yuumi_server_ip')
server_port = config.get('General', 'yuumi_server_port')
click_url = f'http://{yuumi_pc_ip}:{server_port}/click'
spell_url = f'http://{yuumi_pc_ip}:{server_port}/spell'
level_url = f'http://{yuumi_pc_ip}:{server_port}/level'
ALT_KEY = keyboard.Key[config.get('Keys', 'yuumi_enable_controls_key')]
alt_pressed = False
action_delay = 0.5
last_action_time = 0
try:
print('Trying to connect...')
requests.get(f'http://{yuumi_pc_ip}:{server_port}')
print('Connected to Yuumi PC')
except requests.exceptions.ConnectionError:
print('\033[91m' + 'Failed to connect to Yuumi PC. Please check the server IP and try running the script again.' + '\033[0m')
sys.exit()
def send_request(url, json_data):
try:
requests.post(url, json=json_data, timeout=5.0)
except requests.exceptions.Timeout:
print("Request timed out")
def on_key_press(key):
global running, alt_pressed
# Handle key presses for abilities and summoner spells
if alt_pressed and hasattr(key, 'char'):
key_config = {
config.get('Keys', 'spell_q'): 'q',
config.get('Keys', 'spell_w'): 'w',
config.get('Keys', 'spell_e'): 'e',
config.get('Keys', 'spell_r'): 'r',
config.get('Keys', 'spell_d'): 'd',
config.get('Keys', 'spell_f'): 'f',
config.get('Keys', 'open_shop'): 'p',
config.get('Keys', 'tab_info'): 'o',
config.get('Keys', 'go_to_base'): 'b',
config.get('Keys', 'level_up_q'): 'h',
config.get('Keys', 'level_up_w'): 'j',
config.get('Keys', 'level_up_e'): 'k',
config.get('Keys', 'level_up_r'): 'l'
}
action = key_config.get(key.char, None)
if action:
print(f'{key.char} key pressed')
spell_data = {'action': action}
send_request(spell_url, spell_data)
def on_hotkey_press(key):
global alt_pressed
if key == ALT_KEY:
alt_pressed = True
print('ALT key pressed')
def on_hotkey_release(key):
global alt_pressed
if key == ALT_KEY:
alt_pressed = False
print('ALT key released')
def on_click(x, y, button, pressed):
global last_action_time, action_delay, last_action
if alt_pressed and not pressed:
current_time = time.time()
if current_time - last_action_time >= action_delay:
print(f'{button.name} button clicked at ({x}, {y})')
click_data = {'mouse_x': x, 'mouse_y': y, 'button': button.name}
# Create and start a new thread for sending the request
request_thread = threading.Thread(target=send_request, args=(click_url, click_data))
request_thread.start()
last_action_time = current_time
last_action = None
mouse_listener = mouse.Listener(on_click=on_click, daemon=True)
mouse_listener.start()
hotkey_listener = keyboard.Listener(on_press=on_hotkey_press, on_release=on_hotkey_release, daemon=True)
hotkey_listener.start()
keyboard_listener = keyboard.Listener(on_press=on_key_press, daemon=True)
keyboard_listener.start()
while running:
time.sleep(1)