forked from douweschulte/opencontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitor.cs
47 lines (39 loc) · 1.15 KB
/
Monitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace keyboardled_reverse
{
class MonitorControl
{
private const int SC_MONITORPOWER = 61808;
private const int WM_SYSCOMMAND = 274;
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern int PostMessage(int hWnd, int Msg, int wParam, int lParam);
public static void ChangeMonitorState(MonitorMode mode)
{
//Thread.Sleep(200);
PostMessage(-1, 274, 61808, (int)mode);
}
public void MonitorOff()
{
ChangeMonitorState(MonitorMode.MONITOR_OFF);
}
public void MonitorOn()
{
ChangeMonitorState(MonitorMode.MONITOR_ON);
}
public void MonitorStandBy()
{
ChangeMonitorState(MonitorMode.MONITOR_STANBY);
}
public enum MonitorMode
{
MONITOR_ON = -1, // 0xFFFFFFFF
MONITOR_STANBY = 1,
MONITOR_OFF = 2,
}
}
}