Is there any way to detect the monitor state in Windows (on or off)?
GetDevicePowerState sometimes works for monitors. If it's present, you can open the \\.\LCD
device. Close it immediately after you've finished with it.
Essentially, you're out of luck—there is no reliable way to detect the monitor power state, short of writing a device driver and filtering all of the power IRPs up and down the display driver chain. And that's not very reliable either.
How to check if monitor is on or off
This is certainly not possible in cross platform Java, and to be honest isn't really possible in a reliable sense even if we resort to native code.
The (non-reliable) way to do this natively for Windows would be to use GetDevicePowerState
- find it in kernel32.dll
. However, from experiments I did using this function a while back I can say it definitely doesn't work with every monitor, and obviously even if this was reliable it would be a Windows-only solution.
If you do want to go down this route bearing in mind the above limitations, then use MonitorFromPoint
to grab the handle to the primary monitor (pass in a 0,0 as the point and use the MONITOR_DEFAULTTOPRIMARY
flag.)
Detecting if the monitor is powered off
Here is an older answer that might help: How to Determine if LCD Monitor is Turned on From Linux Command Line
Is it possible to detect whether a monitor attached to a Windows PC is actively displaying a certain input?
I don't have any experience developing a VNC application, but maybe a suggestion might start you off on the right path.
Download wmiexplorer
- Run the program
- Here you can explorer different classes in WMI, which will be the lowest level I think you're going to get
- Go to the Query tab and enter the query:
"select * from Win32_DesktopMonitor"
I think this is the information you can use to figure out information about your monitors. (I'm not sure what classes have information that relates to monitors)
In particular, check out Availability for the Win32_DesktopMonitor class.
Update
Running this query on a remote machine Description and DeviceID and Name came back as "Default Monitor." On my real machine, it came back as "Generic PnP Monitor" as well as had a MonitorManufacturer
set, where as the remote machine didn't. You could even go as far as comparing the queried monitor with Screen
resolution or maybe SystemName
returned in the query vs. the system name of the computer running the application.
Use the ManagementObjectSearcher to execute WMI queries.
Edit
You could also do the mapping/cross-checking of devices like the example shown here does. Notice the ClassGUID
is the same between MonitorDesktop and PnPEntity.
Related Topics
What Is a Good Interface for a Linux Device Driver for a Co-Processing Peripheral
What Is The Downside of Updating Arm Ttbr(Translate Table Base Register)
How to Make Libusb Library Visible to Another Program
How to Invoke Any Kernel Function
Using Curl with Commands in Go
How to Execute a Command in a Bash Script and Then Focus The Appearing Window
Sending Snmp2 Trap Message from Linux Command Lne
How to Create a File in Assembly with a Dynamically Specified File Path
"Nothing to Commit (Working Directory Clean)" When a Folder Has Been Added
Linux Kernel Hardware Break Points
Finding and Listing Duplicate Words in a Plain Text File
How to Install and Run Tacotron2 on Ubuntu Wsl
Can't Install Using Yum in Rhel 7.1
Reason of a Directory Size Being Zero
Built-In Kernel Driver Still Need Device Tree
Need Some Advise to Begin Programming on Arm (With Linux) Platform
How to I Detect Whether a Tty Belonging to a Gsm/3G-Modem Is a Data or Control Port