Код: Выделить всё
def focusVscode():
time.sleep(1)
toplist, winlist = [], []
# Focus the VSCode window
def enum_cb(hwnd, results):
winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
win32gui.EnumWindows(enum_cb, toplist)
vscode = [(hwnd, title) for hwnd, title in winlist if 'visual studio code' in title.lower()]
if vscode:
print("\033[32mVSCode found\033[0m")
print(f"VSCode hwnd: {vscode}")
hwnd = vscode[0][0]
# Bring VSCODE window to the foreground
win32gui.SetForegroundWindow(hwnd)
time.sleep(0.15)
Код: Выделить всё
Screenshot saved to: screenshot\screenshot_18.59.07.png
VSCode found
VSCode hwnd: [(593232, 'main.py -
- Visual Studio Code')]
Traceback (most recent call last):
File "c:\Users\\Documents\Python\\main.py", line 72, in
process_screenshot()
~~~~~~~~~~~~~~~~~~^^
File "c:\Users\\Documents\Python\\main.py", line 40, in process_screenshot
focusVscode()
~~~~~~~~~~~^^
File "c:\Users\\Documents\Python\\main.py", line 27, in focusVscode
win32gui.SetForegroundWindow(hwnd)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')
Подробнее здесь: https://stackoverflow.com/questions/793 ... und-window
Мобильная версия