I am working in a laptop reseller company and they are making a control center for their laptops. The keyboards they are using use ACPI methods to change their RGB colors. I have decompiled the previous control center and exported 2 functions to use.
First one is
private void WriteACPI(uint ioctrl, int addr, int data)
{
IntPtr intPtr = CreateFile("\\\\.\\ACPIDriver", [hidden], 3u, IntPtr.Zero, 3u, 0u, IntPtr.Zero);
if (intPtr != IntPtr.Zero)
{
int[] source = new int[2] { addr, data };
IntPtr intPtr2 = Marshal.AllocHGlobal(8);
Marshal.Copy(source, 0, intPtr2, 2);
int outBuffer = 0;
DeviceIoControl(intPtr, ioctrl, intPtr2, 8, ref outBuffer, 4, out var _, IntPtr.Zero);
//Console.WriteLine("out buffer: " + outBuffer);
Marshal.FreeHGlobal(intPtr2);
CloseHandle(intPtr);
}
}
But since there is an (I think) interval in the driver, It gets the commands (changes the keyboard's colors) every approximately 0.7 seconds.
The second function I exported uses WMI commands.
Stopwatch sw = new Stopwatch();
ManagementScope s = new(@"\\.\root\WMI");
ManagementPath p = new("AcpiTest_MULong.InstanceName='ACPI\\PNP0C14\\1_1'");
managementObject = new ManagementObject(s, p, null);
sw.Start();
Value <<= 16;
Addr = Value + Addr;
managementObject.InvokeMethod("GetSetULong", new object[] { Addr });
sw.Stop();
Console.WriteLine("sw in testing : " + sw.ElapsedMilliseconds);
The problem here is that InvokeMethod takes about 180 milliseconds. It is faster than the first method but since I am invoking it for times (for r, g and b values, and for 1 triggering the change value) It gets up to 700 milliseconds again.
I have tried sending 4 ulongs in InvokeMethod object array to make it quick in 180 ms but it just took the first object in that array.
My purpose is to add Gradient change and Music mode etc modes so I should be able to control the keyboard at least 10 times a second (less than 100 ms).
I want to know if there is an alternative method to send ACPI commands to ECRam or a method to make WMI faster. (I have no access to driver's source code, I tried decompiling .sys file with IDAPro and got a C-like file but I couldn't get much information I can use) Thank you.