Skip to content

Commit af8e054

Browse files
committed
Added the move mouse script into Windows backup
1 parent 8f30f67 commit af8e054

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Windows Backup/windows_backup.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import os, sys, shutil, time, hashlib, datetime, json
2+
import threading
3+
import random
4+
try:
5+
import win32api, win32con
6+
except ImportError:
7+
win32api = win32con = None
28
from PySide6.QtWidgets import (
39
QMainWindow, QApplication, QPushButton, QWidget, QFileDialog, QMessageBox,
410
QGridLayout, QProgressDialog, QSpacerItem, QSizePolicy
@@ -89,6 +95,36 @@ def cancel(self):
8995

9096

9197
class MainWindow(QMainWindow):
98+
99+
def setup_keep_screen_on(self, layout, row, cols):
100+
from PySide6.QtWidgets import QCheckBox, QLabel
101+
self.keep_screen_on_checkbox = QCheckBox("Keep Screen On", self)
102+
self.keep_screen_on_checkbox.stateChanged.connect(self.toggle_keep_screen_on)
103+
layout.addWidget(self.keep_screen_on_checkbox, row, 0, 1, cols)
104+
self.keep_screen_on_thread = None
105+
self.keep_screen_on_running = False
106+
# Disable if not Windows or win32api unavailable
107+
if sys.platform != "win32" or not win32api or not win32con:
108+
self.keep_screen_on_checkbox.setEnabled(False)
109+
self.keep_screen_on_checkbox.setToolTip("This feature is only available on Windows with pywin32 installed.")
110+
111+
def toggle_keep_screen_on(self, state):
112+
if state and win32api and win32con:
113+
self.keep_screen_on_running = True
114+
if not self.keep_screen_on_thread or not self.keep_screen_on_thread.is_alive():
115+
self.keep_screen_on_thread = threading.Thread(target=self.keep_screen_on_worker, daemon=True)
116+
self.keep_screen_on_thread.start()
117+
else:
118+
self.keep_screen_on_running = False
119+
120+
def keep_screen_on_worker(self):
121+
while self.keep_screen_on_running:
122+
x = random.randint(0, 100)
123+
y = random.randint(0, 100)
124+
win32api.SetCursorPos((x, y))
125+
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
126+
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
127+
time.sleep(15)
92128
def __init__(self):
93129
super().__init__()
94130

@@ -110,6 +146,9 @@ def __init__(self):
110146
layout.setColumnStretch(c, 1)
111147
# -------------------------------------------------
112148

149+
# Add Keep Screen On checkbox at the top
150+
self.setup_keep_screen_on(layout, 1, cols)
151+
113152
# Set Backup Location Button (spans top row)
114153
self.backup_location_button = QPushButton("Set Backup Location", self)
115154
self.backup_location_button.clicked.connect(self.set_backup_location)

0 commit comments

Comments
 (0)