我看到一个关于 Linux 的问题,如果麦克风上的噪音在很长一段时间内变得太高,屏幕就会变黑。提问者想用它让孩子们在玩游戏时保持安静。 Linux黑屏
如何在 Windows 上使用 C# 完成相同的任务?
这是关闭屏幕的方法:
using System.Runtime.InteropServices; //to DllImport
public int WM_SYSCOMMAND = 0x0112;
public int SC_MONITORPOWER = 0xF170; //Using the system pre-defined MSDN constants that can be used by the SendMessage() function .
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
//To call a DLL function from C#, you must provide this declaration .
private void button1_Click(object sender, System.EventArgs e)
{
SendMessage( this.Handle.ToInt32() , WM_SYSCOMMAND , SC_MONITORPOWER ,2 );//DLL function
}