-
Notifications
You must be signed in to change notification settings - Fork 1
/
brawlhalla_bot.py
83 lines (65 loc) · 1.96 KB
/
brawlhalla_bot.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
from pynput import keyboard
from pynput.keyboard import Key, Controller
import time
from threading import Thread
from random import randint
from random import uniform
bot_running = False
my_keyboard = Controller()
movement_directions = [keyboard.Key.left, keyboard.Key.right, keyboard.Key.up, keyboard.Key.shift]
def press_key():
key_probability = randint(0, 100)
if key_probability < 100:
my_keyboard.press("c")
my_keyboard.release("c")
time.sleep(uniform(0, 0.5))
my_keyboard.press("c")
my_keyboard.release("c")
else:
movement_index = randint(0, 3)
my_keyboard.press("c")
my_keyboard.release("c")
time.sleep(uniform(0, 0.2))
my_keyboard.press("c")
my_keyboard.release("c")
time.sleep(uniform(0, 0.2))
my_keyboard.press(movement_directions[movement_index])
time.sleep(randint(0, 1))
my_keyboard.release(movement_directions[movement_index])
def bot_thread():
my_keyboard.press("c")
my_keyboard.release("c")
while bot_running:
time.sleep(uniform(0, 0.5))
press_key()
def start_bot():
global bot_running
bot_running = True
thread = Thread(target = bot_thread)
thread.start()
def stop_bot():
global bot_running
bot_running = False
exit()
def on_press(key):
try:
if key == keyboard.Key.home:
if not bot_running:
start_bot()
else:
stop_bot()
except AttributeError:
print('special key {0} pressed'.format(
key))
def on_release(key):
return
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
# ...or, in a non-blocking fashion:
listener = keyboard.Listener(
on_press=on_press,
on_release=on_release)
listener.start()