ge9 / IddSampleDriver

Add virtual monitors to your windows 10 device! Works with Oculus software, obs, and any desktop sharing software
733 stars 53 forks source link

Smarter monitor management. #32

Open Entropic-Fiesta opened 5 days ago

Entropic-Fiesta commented 5 days ago

A way to have the virtual monitor dynamically turn on and off depending on external decencies.

For example while i'm normally using my computer it stays off.

Opening steam VR turns the virtual display on, so it's only in use when it's visible to the user. Closes again when closing Steam VR.

Improves UX automatically.

ge9 commented 5 days ago

Thanks for the issue. I found it's possible to turn on and off IddSampleDriver by executing following commands in admin PowerShell:

Enable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false
Disable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false

(The device ID may change, but probably this is often correct) So I think we don't have to provide such a function in IddSampleDriver but can realize such a function using some external automation tool like AutoHotkey.

Entropic-Fiesta commented 4 days ago

Brilliant, however i'm unsure how to implement this into a script. Or a simple file I can run to execute the command. Saving the file as a .ps1 never runs the file even as admin, only running it manually though a PowerShell instance gets the command to correctly function.

ge9 commented 4 days ago
powershell.exe -command start-process 'powershell.exe' '-command Enable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false' -Verb runas

This command runs the previous command as administrator, but of course with UAC dialog, which you may not want. Probably it's better to implement some background program. I tried writing it. This AutoHotkey program, if run with admin privilege, turns on IddSampleDriver when Notepad is open and turns it off when Notepad is closed.

#SingleInstance, Force

loop, {
loop, {
    if WinExist("ahk_class Notepad") {
        Run powershell -command Enable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false,,Hide
        break
    }
    Sleep, 100
}
Sleep, 100
loop, {
    if !WinExist("ahk_class Notepad") {
        Run powershell -command Disable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false,,Hide

        break
    }
    Sleep, 100
}
Sleep, 100
}

Here I used window class to detect Notepad window.

Sometimes it's not so easy to detect only specific windows you want, and I don't know how steam VR windows works, but it's probably possible.

Entropic-Fiesta commented 4 days ago

Brilliant!

Got it working.

#SingleInstance, Force

loop, {
loop, {
    if WinExist("ahk_exe C:\Program Files (x86)\Steam\steamapps\common\SteamVR\bin\win64\vrmonitor.exe") {
        Run powershell -command Enable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false,,Hide
        break
    }
    Sleep, 100
}
Sleep, 100
loop, {
    if !WinExist("ahk_exe C:\Program Files (x86)\Steam\steamapps\common\SteamVR\bin\win64\vrmonitor.exe") {
        Run powershell -command Disable-PnpDevice ROOT\DISPLAY\0000 -Confirm:$false,,Hide

        break
    }
    Sleep, 100
}
Sleep, 100
}

You'll just need to create a shortcut and place it into the windows start up folder with admin rights. :)