toggle key, and that is where you added the function calls. Your
calls at all.
Try this, and still experiment with keyboard numbers.
Code: Select all
settitlematchmode,3 ;this affects IfWinNotActive, 2= partial window match, 3=title must match exactly
keyList := [] ;Declare variables to be used later.
keyList.insert(["2",20500,0]) ;object = "key",interval,nextInterval=0
keyList.insert(["3",90500,0])
keyList.insert(["4",120100,0])
keyList.insert(["r",15100,0])
toggle := false
return ;script stops here and becomes idle, waiting for hotkeys
;; -- This is where your code runs on toggle, and you were missing the KeyboardLED calls.
F12::
toggle := !toggle
if (toggle) {
;loop % keyList.MaxIndex() ;uncomment these 2 lines if you want the delay to start initially or after key press
;keyList[a_index][3] := a_tickcount + keyList[a_index][2] ;reset nextinterval to default interval
settimer,auto,10
KeyboardLED(4, "On", 2) ; On my machine 1 is my active keyboard, your might be 0, or 2...
} else {
settimer,auto,off
KeyboardLED(4, "Off", 2) ; On my machine 1 is my active keyboard, your might be 0, or 2...
}
return
auto:
loop % keyList.MaxIndex() { ;loop through our array of keys
ifWinNotActive,Diablo III ;if window not active then toggle off
{
settimer,auto,off
toggle := false
break
}
if (a_tickcount > keyList[a_index][3]) { ;if enough time has passed since last press do something
keyList[a_index][3] := a_tickcount + keyList[a_index][2] ;set next interval
key := keyList[a_index][1]
send {%key% down}
sleep 50
send {%key% up}
}
}
return
;; -- This will never be called since it isn't in Autoexecute, and you commented out the hotkey.
; F11::
; toggle := !toggle
if (toggle) {
;loop % keyList.MaxIndex() ;uncomment these 2 lines if you want the delay to start initially or after key press
;keyList[a_index][3] := a_tickcount + keyList[a_index][2] ;reset nextinterval to default interval
settimer,auto,10
KeyboardLED(4, "On", 2) ; On my machine 1 is my active keyboard, your might be 0, or 2...
} else {
settimer,auto,off
KeyboardLED(4, "Off", 2) ; On my machine 1 is my active keyboard, your might be 0, or 2...
}
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=0)
{
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")
}
f8::exitapp ;closes program
f9::reload ;reloads program
Edit: It almost looked like you wanted to have two separate toggles, one for the light to change (F11) and one without (F12) but then just commented out the hotkey for the lighted one.