mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
ACPI events listener
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO.Pipes;
|
using System.IO.Pipes;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@@ -121,11 +122,48 @@ public class ASUSWmi
|
|||||||
private const uint GENERIC_WRITE = 0x40000000;
|
private const uint GENERIC_WRITE = 0x40000000;
|
||||||
private const uint OPEN_EXISTING = 3;
|
private const uint OPEN_EXISTING = 3;
|
||||||
private const uint FILE_ATTRIBUTE_NORMAL = 0x80;
|
private const uint FILE_ATTRIBUTE_NORMAL = 0x80;
|
||||||
|
private const uint FILE_FLAG_OVERLAPPED = 0x40000000;
|
||||||
private const uint FILE_SHARE_READ = 1;
|
private const uint FILE_SHARE_READ = 1;
|
||||||
private const uint FILE_SHARE_WRITE = 2;
|
private const uint FILE_SHARE_WRITE = 2;
|
||||||
|
|
||||||
private IntPtr handle;
|
private IntPtr handle;
|
||||||
|
|
||||||
|
// Event handling attempt
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
|
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
|
private static extern bool WaitForSingleObject(IntPtr hHandle, int dwMilliseconds);
|
||||||
|
|
||||||
|
private IntPtr eventHandle;
|
||||||
|
|
||||||
|
// still works only with asus optimization service on , if someone knows how to get ACPI events from asus without that - let me know
|
||||||
|
public void RunListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
eventHandle = CreateEvent(IntPtr.Zero, false, false, "ATK Event");
|
||||||
|
|
||||||
|
byte[] outBuffer = new byte[16];
|
||||||
|
byte[] data = new byte[8];
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
data[0] = BitConverter.GetBytes(eventHandle.ToInt32())[0];
|
||||||
|
data[1] = BitConverter.GetBytes(eventHandle.ToInt32())[1];
|
||||||
|
|
||||||
|
result = Control (0x222400, data, outBuffer);
|
||||||
|
Debug.WriteLine(result + ":" + BitConverter.ToString(data) + "|" + BitConverter.ToString(outBuffer));
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
WaitForSingleObject(eventHandle, Timeout.Infinite);
|
||||||
|
Control(0x222408, new byte[0], outBuffer);
|
||||||
|
int code = BitConverter.ToInt32(outBuffer);
|
||||||
|
Logger.WriteLine("Code: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ASUSWmi()
|
public ASUSWmi()
|
||||||
{
|
{
|
||||||
handle = CreateFile(
|
handle = CreateFile(
|
||||||
@@ -134,19 +172,21 @@ public class ASUSWmi
|
|||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
IntPtr.Zero,
|
IntPtr.Zero,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
||||||
IntPtr.Zero
|
IntPtr.Zero
|
||||||
);
|
);
|
||||||
|
|
||||||
if (handle == new IntPtr(-1))
|
if (handle == new IntPtr(-1))
|
||||||
{
|
{
|
||||||
throw new Exception("Can't connect to ACPI");
|
throw new Exception("Can't connect to ACPI");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Control(uint dwIoControlCode, byte[] lpInBuffer, byte[] lpOutBuffer)
|
public bool Control(uint dwIoControlCode, byte[] lpInBuffer, byte[] lpOutBuffer)
|
||||||
{
|
{
|
||||||
uint lpBytesReturned = 0;
|
uint lpBytesReturned = 0;
|
||||||
bool result = DeviceIoControl(
|
return DeviceIoControl(
|
||||||
handle,
|
handle,
|
||||||
dwIoControlCode,
|
dwIoControlCode,
|
||||||
lpInBuffer,
|
lpInBuffer,
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ namespace GHelper
|
|||||||
SettingsToggle(action);
|
SettingsToggle(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Task.Run(wmi.RunListener);
|
||||||
|
|
||||||
Application.Run();
|
Application.Run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user