I have two monitors (HP EliteDisplay E190i), both are connected to two computers (2x VGA + DP).
These monitors also support DVI, so instead of having a stupid toggle button, every time I wish to change between computers I have to navigate through the monitors' menu. I used to have dumber monitors and switching was really easy, but I just can't get used to the whole navigation thing - it often gets confusing...
So here's the deal - I want to be able to quickly switch between the computers by executing a command. Obviously this cannot be done directly (the computers are not connected to each other in any way), but when the monitors enter power saving mode (or when the OS turns them off), the monitors start scanning for available inputs. This way they would lock into the other computer and problem solved.
Enough introduction though, I've tried this solution and it worked great, but it wasn't perfect:
- It had a fade out animation which took a couple seconds before the monitor actually turned off
- I had to not touch the mouse/keyboard for the duration of the above fade out animation, otherwise it would get canceled
I tried disabling the input according to this answer before sending the monitor to sleep, then re-enabling it after 5 seconds, but that also didn't work because:
- It required me to run the application with admin rights, otherwise input would not be blocked
- Even though the input was blocked when running with admin rights, I could still move the mouse or hit some keys on the keyboard during the fade out animation to cancel it (even though the pointer did not move, or the keyboard input was ignored).
Here's my code:
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern int BlockInput(int fBlockIt);
static void Main()
{
SendMessage(0xFFFF, 0x112, 0xF170, 2);
try
{
int result = BlockInput(1);
Console.WriteLine(result);
Thread.Sleep(5000);
}
finally
{
BlockInput(0);
}
}
I use Windows 7 Enterprise x64 on both computers.
Is there any way to get this whole ceremony to work?