Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
尝试让鼠标移动。当我通过敲击键盘唤醒 Windows 7 系统时,屏幕会保持黑色,直到我移动鼠标。
Cursor.Position = new Point(x, y);
Try making the mouse move. When i wake up my Windows 7 system with a tap on the keyboard the screen stays black until i move the mouse.
对我来说,使用 pinvoke 调用 SendMessage 效果很好。csharp 的代码示例:
SendMessage
using System; using System.Runtime.InteropServices; namespace MyDummyNamespace { class MyProgram { private static int Main(string[] args) { // your program code here // ... NativeMethods.MonitorOff(); System.Threading.Thread.Sleep(5000); NativeMethods.MonitorOn(); return 0; } private static class NativeMethods { internal static void MonitorOn() { SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (IntPtr)MONITOR_ON); } internal static void MonitorOff() { SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (IntPtr)MONITOR_OFF); } [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); private static int MONITOR_ON = -1; private static int MONITOR_OFF = 2; private static int MONITOR_STANBY = 1; private static IntPtr HWND_BROADCAST = new IntPtr(0xffff); private static UInt32 WM_SYSCOMMAND = 0x0112; private static IntPtr SC_MONITORPOWER = new IntPtr(0xF170); } } }
上述解决方案受到以下答案的启发:https://stackoverflow.com/a/332733/1468842
for me it works fine to use pinvoke to call SendMessage.code example for csharp:
the above solution was inspired by this answer: https://stackoverflow.com/a/332733/1468842
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
尝试让鼠标移动。当我通过敲击键盘唤醒 Windows 7 系统时,屏幕会保持黑色,直到我移动鼠标。
Try making the mouse move. When i wake up my Windows 7 system with a tap on the keyboard the screen stays black until i move the mouse.
对我来说,使用 pinvoke 调用
SendMessage
效果很好。csharp 的代码示例:
上述解决方案受到以下答案的启发:https://stackoverflow.com/a/332733/1468842
for me it works fine to use pinvoke to call
SendMessage
.code example for csharp:
the above solution was inspired by this answer: https://stackoverflow.com/a/332733/1468842