-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
120 lines (89 loc) · 3.16 KB
/
main.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
from modules import button_bindings as bindings
from modules import xbox_controller as xbox_controller
from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController
import pydirectinput
import time
import ctypes, sys
def is_admin():
# return True
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
class ButtonFunctions:
def __init__(self):
self.left_mouse_state = 0
self.program_active_state = True
def key_press(self, button):
keyboard.press(button)
keyboard.release(button)
def change_mouse_left_state(self, value):
if self.left_mouse_state != value:
self.left_mouse_state = value
if value == 1:
pydirectinput.mouseDown()
else:
pydirectinput.mouseUp()
def flip_active_state(self):
if self.program_active_state:
self.program_active_state = False
else:
self.program_active_state = True
print('Program State: ' + ('Paused' if not self.program_active_state else 'Active'))
def mouse_press(self, button):
mouse.press(button)
mouse.release(button)
def single_press(self, button):
if type(button) == Button:
self.mouse_press(button)
elif type(button) == Key:
self.key_press(button)
else:
os.startfile(button)
if __name__ == '__main__' and is_admin():
keyboard = KeyboardController()
mouse = MouseController()
Xbox = xbox_controller.XboxController()
button_functions = ButtonFunctions()
button_update_cycle = 13
button_update_counter = 0
enable_function = True
while 1:
controller_values = Xbox.get_value()
if controller_values['BTN_THUMBR'] and controller_values['BTN_THUMBL']:
button_functions.flip_active_state()
time.sleep(.3)
if button_functions.program_active_state:
##mouse movement
move_x = controller_values['ABS_X']
move_y = controller_values['ABS_Y']
deadzone = bindings.joystick_deadzone
if abs(move_x) < deadzone:
move_x = 0
if abs(move_y) < deadzone:
move_y = 0
if controller_values['BTN_THUMBL'] == 1:
mouse.scroll(0, move_y * .4)
else:
base_sens = bindings.joystick_sensitivity_base_multiplier
sens_curve = bindings.joystick_applied_power_curve
mouse.move(pow(move_x * base_sens, sens_curve), pow(move_y * -base_sens, sens_curve))
##binary_buttons
if button_update_counter >= button_update_cycle:
for key in bindings.button_binary_keys.keys():
action = bindings.button_binary_keys[key]
if key in ['ABS_HAT0Y', 'ABS_HAT0X']:
action = action[controller_values[key]]
if action == Button.left:
button_functions.change_mouse_left_state(controller_values[key])
elif action != None and abs(controller_values[key]) > .02:
button_functions.single_press(action)
button_update_counter=0
button_update_counter += 1
time.sleep(0.01)
else:
time.sleep(.01)
else:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)