-
Notifications
You must be signed in to change notification settings - Fork 6
/
SystemHandler.cs
97 lines (69 loc) · 3.05 KB
/
SystemHandler.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using ProverbTeleprompter.Helpers;
using Tools.API.Messages.wParam;
using System.Management;
using System.Linq;
namespace ProverbTeleprompter
{
public static class SystemHandler
{
private const int WM_KEYDOWN = 0x0100;
private const int WM_APPCOMMAND = 0x0319;
public static event EventHandler<RemoteButtonPressedEventArgs> RemoteButtonPressed;
public static event EventHandler<KeyPressEventArgs> KeyDown;
public static event EventHandler<DisplayChangedEventArgs> DisplayAttached;
public static event EventHandler<DisplayChangedEventArgs> DisplayRemoved;
[StructLayout(LayoutKind.Sequential)]
public struct DEV_BROADCAST_VOLUME
{
public int dbcv_size;
public int dbcv_devicetype;
public int dbcv_reserved;
public int dbcv_unitmask;
}
public static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_APPCOMMAND)
{
var command = Tools.API.Messages.lParam.Macros.GET_APPCOMMAND_LPARAM(lParam.ToInt32());
if(RemoteButtonPressed != null)
{
RemoteButtonPressed.Invoke(null, new RemoteButtonPressedEventArgs { AppCommand = command});
}
}
return IntPtr.Zero;
}
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr RegisterDeviceNotification(IntPtr IntPtr, IntPtr NotificationFilter, Int32 Flags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern uint UnregisterDeviceNotification(IntPtr hHandle);
public static void RegisterHidNotification(IntPtr handle)
{
Win32.DEV_BROADCAST_DEVICEINTERFACE dbi = new
Win32.DEV_BROADCAST_DEVICEINTERFACE();
int size = Marshal.SizeOf(dbi);
dbi.dbcc_size = size;
dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE;
dbi.dbcc_reserved = 0;
dbi.dbcc_classguid = Win32.GUID_DEVINTERFACE_HID;
dbi.dbcc_name = "";
IntPtr buffer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(dbi, buffer, true);
IntPtr r = Win32.RegisterDeviceNotification(handle, buffer,
Win32.DEVICE_NOTIFY_WINDOW_HANDLE | Win32.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
if(r == IntPtr.Zero){
}
}
public static DisplayDetails GetMonitorInformation(string dbcc_name)
{
DisplayDetails details = DisplayDetails.GetMonitorDetails().Where(x => dbcc_name.ToLower().Contains(x.PnPID.ToLower())).FirstOrDefault();
return details;
}
}
}