CM Devastator 键盘 - 打开背光,关闭滚动锁定

CM Devastator 键盘 - 打开背光,关闭滚动锁定

所以我最近购买了一个 CM Devastator 键盘,它有 LED 背光。

问题是,背光是通过 ScrollLock 键来切换的。因此,您必须将 ScrollLock 设置为“开”,才能使用背光。

但对于 Excel 的重度用户来说,这行不通。

所以我尝试使用此线程中提供的库编写脚本。但是,无论我将 KeyboardLED 命令更改为哪个 KeyboardClass,它似乎都不起作用。

~ScrollLock::

If (GetKeyState("Scrolllock", "T"))
    KeyboardLED(1, on, kbd=0)
        Else
    KeyboardLED(1, off, kbd=0)
Return

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)

  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }

  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )

  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}

除了前几行,其余的都是从这个帖子里复制过来的。我做错了什么?

我正在使用 Windows 7 x64 和 Autohotkey_L。

答案1

据说,您应该能够在注册表中搜索正确的键盘 ID。在注册表编辑器中搜索KeyboardClass。这应该会得到类似 的结果\Device\KeyboardClass0。我自己有KeyboardClass0KeyboardClass1,1 对我有用。它应该是末尾的数字之一。

您也可以尝试这个脚本来查看该功能是否适合您。

Loop, 10
{
    kbdIndex := A_Index
    TrayTip, Trying %A_index%, , 1
    Loop, 3 ; flash all LEDs
     {
     KeyboardLED(4,"on", kbdIndex)
     Sleep, 500
     KeyboardLED(4,"off", kbdIndex)
     Sleep, 500
     }

    Sleep 1000
    Return
}

相关内容