-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
170 lines (144 loc) · 5.79 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import PySimpleGUI as sg
import pyautogui
import time
import threading
import keyboard
import json
cycle = 0
def move_cursor(interval, unit):
multiplier = 1
if unit == 'Minutes':
multiplier = 60
elif unit == 'Hours':
multiplier = 3600
while mouse_afk_active:
pyautogui.move(1, 0, duration=0.1)
time.sleep(interval * multiplier)
pyautogui.move(-1, 0, duration=0.1)
time.sleep(interval * multiplier)
def press_key(interval, key):
while keyboard_afk_active:
keyboard.press(key)
keyboard.release(key)
time.sleep(interval)
def toggle_afk():
global afk_active
if afk_active:
stop_afk()
else:
start_afk()
def start_afk():
global afk_active, mouse_afk_active, keyboard_afk_active
interval_text = window['-INTERVAL-'].get()
if not is_number(interval_text):
# Change the highlight color of the text input border to red if it's not a number
window['-INTERVAL-'].Widget.configure(highlightcolor='red', highlightbackground='red', insertbackground='white', highlightthickness=1)
return # Don't proceed with the action if the interval is not a valid number
else:
# Restore the text input border color if it's a valid number
window['-INTERVAL-'].Widget.configure(highlightcolor="White", highlightbackground='#373737', insertbackground='white', highlightthickness=1)
interval = int(interval_text)
unit = values['-UNIT-']
if values['-MOUSE_AFK-']:
mouse_afk_active = True
thread = threading.Thread(target=move_cursor, args=(interval, unit))
thread.daemon = True
thread.start()
if values['-KEYBOARD_AFK-'] and assigned_key is not None:
keyboard_afk_active = True
thread = threading.Thread(target=press_key, args=(interval, assigned_key))
thread.daemon = True
thread.start()
afk_active = True
window['-START_STOP-'].update('Stop')
def stop_afk():
global afk_active, mouse_afk_active, keyboard_afk_active
afk_active = False
mouse_afk_active = False
keyboard_afk_active = False
window['-START_STOP-'].update('Start')
def define_key():
layout = [
[sg.Text('Press any key')],
]
window = sg.Window('Define Key', layout, finalize=True)
event, values = window.read()
if event == sg.WINDOW_CLOSED:
window.close()
return None
window.close()
return event
def is_number(text):
try:
float(text)
return True
except ValueError:
return False
def display_help():
sg.popup("Instructions:",
"1. Interval for cursor movement: Specify how much time should pass before the cursor moves automatically.",
"2. Mouse AFK: Activate automatic cursor movement.",
"3. Keyboard AFK: Activate automatic pressing of the specified key.",
"4. Key to press: Show the assigned key for the Keyboard AFK function.",
"5. Start/Stop: Start or stop the Mouse AFK and/or Keyboard AFK function.",
"* The cursor will move 1 pixel to the left and 1 pixel to the right.", )
# Add custom theme
sg.theme_add_new('CustomDarkTheme', {'BACKGROUND': '#373737',
'TEXT': '#FFFFFF',
'INPUT': '#474747',
'TEXT_INPUT': '#FFFFFF',
'SCROLL': '#515151',
'BUTTON': ('white', '#474747'),
'PROGRESS': ('#01826B', '#D0D0D0'),
'BORDER': 0, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0})
# Apply custom theme
sg.theme("CustomDarkTheme")
# Load the assigned key from a file if available
try:
with open('assigned_key.txt', 'r') as file:
assigned_key = file.read().strip()
except FileNotFoundError:
assigned_key = 'alt'
mouse_afk_active = False
keyboard_afk_active = False
afk_active = False
# Define font for the entire window
font_style = ('Arial', 13)
layout = [
[sg.Text('Interval for cursor movement:', size=(30, 1), justification='center', font=font_style)],
[sg.InputText('5', key='-INTERVAL-', size=(10, 1), justification='center'),
sg.InputOptionMenu(['Seconds', 'Minutes', 'Hours'], default_value='Minutes', key='-UNIT-', size=(10, 1))],
[sg.Checkbox('Mouse AFK', default=True, key='-MOUSE_AFK-'),
sg.Checkbox('Keyboard AFK', default=False, key='-KEYBOARD_AFK-')],
[sg.Text('Key to press:', size=(30, 1), justification='center', font=font_style)],
[sg.Text(assigned_key.upper(), key='-ASSIGNED_KEY-', size=(10, 1), justification='center')],
[sg.Button('Help', size=(10, 1), font=font_style),
sg.Button('Start', size=(10, 1), key='-START_STOP-', font=(font_style[0], font_style[1], 'bold')),
sg.Button('Define Key', size=(10, 1), font=font_style)]
]
window = sg.Window('Anti AFK', layout, element_justification='c', icon="ico.ico", size=(340, 183))
while True:
event, values = window.read(timeout=cycle * 100000)
try:
window['-INTERVAL-'].Widget.configure(highlightcolor="White", highlightbackground='White', insertbackground='white', highlightthickness=1)
except:
pass
if event == sg.WINDOW_CLOSED:
break
if event == 'Define Key':
window.hide()
sg.popup_quick_message('Press any key', auto_close_duration=3)
assigned_key = keyboard.read_event().name
window['-ASSIGNED_KEY-'].update(assigned_key.upper())
window.un_hide()
# Save the assigned key to a file
with open('assigned_key.txt', 'w') as file:
file.write(assigned_key)
if event == '-START_STOP-':
toggle_afk()
elif event == 'Help':
display_help()
cycle = cycle + 1
if cycle > 100000:
cycle = 100000
window.close()