I want to minimize all open windows and / or show the desktop on a Windows 10 machine from within a python script. I had a look in the win32api, win32con, win32gui but cannot find anything appropriate. Any idea appreciated. Thanks
I want to minimize all open windows and / or show the desktop on a Windows 10 machine from within a python script. I had a look in the win32api, win32con, win32gui but cannot find anything appropriate. Any idea appreciated. Thanks
Pyautogui is a great module for stimulating keyboard clicks and mouse clicks. To install it, try this command in the terminal. pip install PyAutoGUI
Using pyautogui, you can stimulate a virtual click in 2 ways. Choose which one works best for you:
1:
import pyautogui
pyautogui.hotkey('winleft', 'd')
2:
import pyautogui
pyautogui.keyDown('winleft')
pyautogui.press('d')
pyautogui.keyUp('winleft')
Sometimes the first one doesn't work, so if it doesn't, try the second one.
If you want to use WinApi to implement keyboard emulation, you can use the keybd_event function.
code:
import win32api
win32api.keybd_event(0x5B, 0, ) # LWIN
win32api.keybd_event(0x44, 0, ) # D
win32api.keybd_event(0x5B, 0, 2)
win32api.keybd_event(0x44, 0, 2)
Of course, you should probably use SendInput, but it is a bit complicated to use in python.
You can refer to this thread : How to generate keyboard events in Python?