Search code examples
pythonpython-3.xwindowswindows-10desktop

How to detect which windows desktop I'm on in python3?


In Windows 10 you can create multiple desktops and switch between them. I want to run a python3 code when I am on a certain desktop. How do I detect which desktop I'm on?


Solution

  • Download the VirtualDesktopAccessor.dll from here and put it in your working directory.

    Run the following code:

    import ctypes
    
    vda = ctypes.WinDLL("VirtualDesktopAccessor.dll")
    num = vda.GetCurrentDesktopNumber()
    print(num)