c# - 以可编程方式唤醒睡眠中的 Windows 10 屏幕
问题描述
所以我尝试了几种不同的方法来唤醒我的显示器。我想从外部服务唤醒我的显示器(我在“更改 PC 睡眠时间”->“屏幕”->“插入后关闭”中设置为 15 分钟),作为唤醒 3 个屏幕需要 45-60 秒。我想在走廊中检测到运动时调用此 API,但该部分已设置并完成。
所以很自然(我猜),我设置了一个调用 Windows API 的 .NET 5.0 Web API。目前它只是将光标移动 1 个像素,但不幸的是,这似乎并没有唤醒屏幕(可能是因为 Windows 知道是软件做到了)。我还尝试将光标移动许多像素,但这也没有做任何事情。
我是这样做的:
[ApiController]
[Route("[controller]")]
public class MouseController : ControllerBase
{
[DllImport("User32.dll", SetLastError = false)]
public static extern IntPtr GetDesktopWindow();
[DllImport("User32.Dll")]
public static extern long SetCursorPos(int x, int y);
[DllImport("User32.Dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("User32.Dll")]
public static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
public POINT(int X, int Y)
{
x = X;
y = Y;
}
}
[HttpGet("[action]")]
public async Task WakeMonitors()
{
POINT p;
if (GetCursorPos(out p))
{
IntPtr desktopWinHandle = GetDesktopWindow();
ClientToScreen(desktopWinHandle, ref p);
SetCursorPos(p.x, p.y - 1);
}
}
}
它出奇地有效,但正如我所说,它不会将我的显示器从睡眠中唤醒。
那我该怎么做呢?我不关心我必须做的黑客攻击,但如果我可以调用一些 Windows API 并告诉它“从睡眠中唤醒监视器”,那就太好了。
解决方案
推荐阅读
- python - 在 Python/OpenCV 中将系列视频附加在一起
- python - 从 LDAP 预填充 Django 用户
- android - 权限顺序
- r - 合并三个不同大小、列名的数据集
- javascript - socket.io、vTiger 和 csrf-magic.js。CORS 问题
- nginx - 使用 js_body_filter njs 指令时 Nginx 不返回响应正文
- python - 欧几里得算法 - 我在做什么?蟒蛇约翰泽尔
- flutter - 如何在 Flutter 中使用 PopupMenu Item 设置分隔符和分隔符颜色?
- typescript - 这里的某个地方是一个递归调用,我似乎找不到它。我必须使用 Typescript 和 Lodash 而不是 SuiteScript
- html - jQuery .wrap() 相邻按钮 HTML