Reputation: 3
Im trying to run a python script that will move files in the background while in a fullscreen game. When the program runs I want it to not tab me out of the game. Im on Windows 10.
I can run the program through a button on my mouse, but when it runs the command prompt is briefly opened and the game unfocuses.
Upvotes: 0
Views: 247
Reputation: 3
I gave up on having it possibly open in the background after seeing that it might be impossible or require threading. Instead, I had the code focus on the game when it finished running.
def find_window(title):
return win32gui.FindWindow(None, title)
def bring_to_foreground(hwnd):
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE) # Restore the window if minimized
win32gui.SetForegroundWindow(hwnd)
app_title = "APPLICATION_NAME"
app_window = find_window(app_title)
if app_window:
bring_to_foreground(app_window)
print(f"Window '{app_title}' brought to the foreground.")
else:
print(f"Window '{app_title}' not found.")
Replace the application name with the name of the application desired.
Upvotes: 0
Reputation: 39
Type this command on your cmd:
start /b python your_script.py
/b
switch tells the cmd to start the script in the background.
Upvotes: 0