Jademalo

Untitled

Aug 4th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. /*
  2. Keyboard LED control for AutoHotkey_L
  3. http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000
  4. KeyboardLED(LEDvalue, "Cmd", Kbd)
  5. LEDvalue - ScrollLock=1, NumLock=2, CapsLock=4
  6. Cmd - on/off/switch
  7. Kbd - index of keyboard (probably 0 or 2)
  8. */
  9.  
  10. KeyboardLED(LEDvalue, Cmd, Kbd=0)
  11. {
  12. SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  13. h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
  14.  
  15. If Cmd= switch ;switches every LED according to LEDvalue
  16. KeyLED:= LEDvalue
  17. If Cmd= on ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
  18. KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  19. If Cmd= off ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
  20. {
  21. LEDvalue:= LEDvalue ^ 7
  22. KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  23. }
  24.  
  25. success := DllCall( "DeviceIoControl"
  26. , "ptr", h_device
  27. , "uint", CTL_CODE( 0x0000000b ; FILE_DEVICE_KEYBOARD
  28. , 2
  29. , 0 ; METHOD_BUFFERED
  30. , 0 ) ; FILE_ANY_ACCESS
  31. , "int*", KeyLED << 16
  32. , "uint", 4
  33. , "ptr", 0
  34. , "uint", 0
  35. , "ptr*", output_actual
  36. , "ptr", 0 )
  37.  
  38. NtCloseFile(h_device)
  39. return success
  40. }
  41.  
  42. CTL_CODE( p_device_type, p_function, p_method, p_access )
  43. {
  44. Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
  45. }
  46.  
  47.  
  48. NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
  49. {
  50. VarSetCapacity(objattrib,6*A_PtrSize,0)
  51. VarSetCapacity(io,2*A_PtrSize,0)
  52. VarSetCapacity(pus,2*A_PtrSize)
  53. DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  54. NumPut(6*A_PtrSize,objattrib,0)
  55. NumPut(&pus,objattrib,2*A_PtrSize)
  56. status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
  57. ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
  58. ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  59. return % fh
  60. }
  61.  
  62. NtCloseFile(handle)
  63. {
  64. return DllCall("ntdll\ZwClose","ptr",handle)
  65. }
  66.  
  67.  
  68. SetUnicodeStr(ByRef out, str_)
  69. {
  70. VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  71. StrPut(str_,&out,"utf-16")
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. ScrollLock:: ; Scroll lock will toggle the state
  81. if (mediaState = 1)
  82. {
  83. mediaState := 0
  84. KeyboardLED(1,"off",4)
  85. }
  86. else
  87. {
  88. mediaState := 1
  89. KeyboardLED(1,"on",4)
  90. }
  91. return
  92.  
  93. #If (mediaState = 1)
  94.  
  95. Insert::Media_Prev
  96. Home::Media_Play_Pause
  97. PgUp::Media_Next
  98. Delete::Volume_Mute
  99. End::Volume_Down
  100. PgDn::Volume_Up
Advertisement
Add Comment
Please, Sign In to add comment