如何调用笔记本键盘灯的驱动
以我华硕的笔记本电脑为例,通常是根据armoury crate来控制键盘灯。我希望自己实现一个(比如说按下某个键让键盘灯亮起)。我下一步应该怎么做,应该怎么分析相关驱动的调用方式? https://www.52pojie.cn/thread-1455086-1-1.html看看大佬的分析贴 看了下好像键盘灯是没法单个打开的,所以我准备利用capslock上的灯,按照了一个“让USB键盘的LED灯听你的!(不干扰使用)“的教程,但是这边遇到一个设备路径的问题,我不知道填什么
”namespace KeybdLightCtrl
{
internal class StatusChange
{
static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,
IntPtr lpInBuffer, uint nInBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
out uint lpBytesReturned, IntPtr lpOverlapped);
private const uint GENERIC_WRITE = 0x40000000;
private const uint OPEN_EXISTING = 3;
private const uint FILE_ANY_ACCESS = 0;
private const uint METHOD_BUFFERED = 0;
private const uint FILE_DEVICE_KEYBOARD = 0x0000000b;
private uint IOCTL_KEYBOARD_SET_INDICATORS = CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0002, METHOD_BUFFERED, FILE_ANY_ACCESS);
private uint IOCTL_KEYBOARD_QUERY_TYPEMATIC = CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0008, METHOD_BUFFERED, FILE_ANY_ACCESS);
private uint IOCTL_KEYBOARD_QUERY_INDICATORS = CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0010, METHOD_BUFFERED, FILE_ANY_ACCESS);
static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
{
return ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method);
}
public void change()
{
IntPtr hKeyboard = CreateFile(@"\\.\Device\00000088", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if (hKeyboard == IntPtr.Zero || hKeyboard.ToInt32() == -1)
{
MessageBox.Show("failed to open keybd device");
return;
}
//用marshal分配一块空内存(pbuffer)
KeyboardIndicatorParameters buffer = new KeyboardIndicatorParameters();
buffer.UnitId = 0;
buffer.LedFlags = Locks.None;
IntPtr pbuffer = Marshal.AllocHGlobal(Marshal.SizeOf(buffer));
uint retlen;
DeviceIoControl(hKeyboard, IOCTL_KEYBOARD_QUERY_INDICATORS, IntPtr.Zero, 0, pbuffer, (uint)Marshal.SizeOf(buffer), out retlen, IntPtr.Zero);
//解析pbuffer,转换capslock灯状态
KeyboardIndicatorParameters updatedBuffer = Marshal.PtrToStructure<KeyboardIndicatorParameters>(pbuffer);
Locks mask = Locks.KeyboardCapsLockOn;
updatedBuffer.LedFlags = updatedBuffer.LedFlags ^ mask;
Marshal.StructureToPtr(updatedBuffer, pbuffer, false);
//设置新状态
bool success = DeviceIoControl(hKeyboard, IOCTL_KEYBOARD_SET_INDICATORS, pbuffer, (uint)Marshal.SizeOf(buffer), IntPtr.Zero, 0, out retlen, IntPtr.Zero);
if (!success)
{
MessageBox.Show("failed");
return;
}
return;
}
struct KeyboardIndicatorParameters
{
public ushort UnitId;
public Locks LedFlags;
}
public enum Locks : ushort
{
None = 0,
KeyboardScrollLockOn = 1,
KeyboardNumLockOn = 2,
KeyboardCapsLockOn = 4
}
}
}
就是IntPtr hKeyboard = CreateFile(@"\\.\Device\00000088", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);这行第一个参数。我device manager的keyboard里面有四个键盘,三个HID一个PS/2。求教应该填什么进去?
我是联系朝阳K系列的,不知道有没有灯?
我的笔记本也需要按 Fn + F6 禁用触摸板!因为打字时误触时光标会跑,休眠后也要再按一次热键。也没想到有什么办法可以永久禁用触摸板。 chishingchan 发表于 2024-6-28 08:55
我的笔记本也需要按 Fn + F6 禁用触摸板!因为打字时误触时光标会跑,休眠后也要再按一次热键。也没想到有 ...
电脑设置里面可以设置有外接鼠标时停用触摸板(因个人电脑而异) chishingchan 发表于 2024-6-28 08:55
我的笔记本也需要按 Fn + F6 禁用触摸板!因为打字时误触时光标会跑,休眠后也要再按一次热键。也没想到有 ...
直接禁用驱动试试 chishingchan 发表于 2024-6-28 08:55
我的笔记本也需要按 Fn + F6 禁用触摸板!因为打字时误触时光标会跑,休眠后也要再按一次热键。也没想到有 ...
禁用驱动 ,想用了再去启用。 开源的g-helper可以研究一下 键盘灯确实可以玩出花来。
页:
[1]
2