J.Kaita
J.Kaita

Reputation: 25

How to minimize all open apps using python

I am trying to achieve a functionality in which I can minimize other apps leaving only my current active window on my app using python. How can this be done?

A similar function is done using Windows + Home key, but how can I do this in my app?

Platform : WxPython O.s : Windows

Upvotes: 0

Views: 1156

Answers (1)

Osadhi Virochana
Osadhi Virochana

Reputation: 1302

First, you need to pynput by using

pip install pynput

Now use this code to press Windows + Home key

from pynput.keyboard import Key, Controller

keyboard = Controller()

keyboard.press(Key.cmd)
keyboard.press(Key.home)
keyboard.release(Key.home)
keyboard.release(Key.cmd)

Then add delay to switch the app you want. Otherwise, it will keep only the python shell. I am adding 5 seconds delay you can change it as you want.

from pynput.keyboard import Key, Controller
from time import sleep

keyboard = Controller()

sleep(5)  # this is 5 seconds change as you want

keyboard.press(Key.cmd)
keyboard.press(Key.home)
keyboard.release(Key.home)
keyboard.release(Key.cmd)

Upvotes: 4

Related Questions