gpt4 book ai didi

electron - Electronjs如何检测显示器/屏幕是否关闭

转载 作者:行者123 更新时间:2023-12-03 12:38:46 28 4
gpt4 key购买 nike

我们如何检测显示器是否关闭。 Electron提供了electron.screen API,我们可以在其中检索所有显示的electron.screen.getAllDisplays(),但此处提供的信息并不包含有关显示器电源状态的信息:

[{
id: 2528732444,
bounds: { x: 0, y: 0, width: 1920, height: 1080 },
workArea: { x: 0, y: 0, width: 1920, height: 1040 },
accelerometerSupport: 'unknown',
monochrome: false,
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:IEC61966_2_1, matrix:RGB, range:FULL}',
depthPerComponent: 8,
size: { width: 1920, height: 1080 },
workAreaSize: { width: 1920, height: 1040 },
scaleFactor: 1,
rotation: 0,
internal: false,
touchSupport: 'unknown'
},
...
]
如果显示器未插入PC,则不会列出它。但是,如果将监视器插入PC并关闭电源,它将以 electron.screen.getAllDisplays()列出它,但不提供其状态。

最佳答案

这是不可能的,即使显示器关闭,诸如DVI或HDMI之类的东西仍会报告屏幕已连接(这就是为什么它显示在getAllDisplays()中)的原因。
我唯一能想到的选择是运行一个shell脚本来访问
Win32 API,但这将不再基于Electron。
您将使用Power Setting GUIDs of Windows

GUID_CONSOLE_DISPLAY_STATE

6FE69556-704A-47A0-8F24-C28D936FDA47

The current monitor's display state has changed.

Windows 7, Windows Server 2008 R2, Windows Vista and Windows Server 2008: This notification is available starting with Windows 8 and Windows Server 2012.

The Data member is a DWORD with one of the following values.

0x0 - The display is off.

0x1 - The display is on.

0x2 - The display is dimmed.

关于electron - Electronjs如何检测显示器/屏幕是否关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64786813/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com