I would like to be able to press a key on the keyboard once and have an autohotkey script hold that key down, until the keyboard key is pressed again to release it. I have tried several different ways of accomplishing this but so far at best I can only get the particular key to be pressed once and then it stops, attempts to Send {WhateverKeyboardKey Down} have failed to actually hold down and continually send the particular keys; additionally I'm concerned succeeding in getting the script to hold down a key may dump the script into an uncontrollable loop and perhaps make it ignore the follow up key press intended to toggle off the particular key which is why one of my attempts tried using WASD and IJKL to toggle Up, Down, Left, Right. Any help would be appreciated. All of my attempts use specifically identified keys, but I imagine there would be a way to use %A_ThisHotKey% to make the toggling script generic so that it would work for any key pressed on the keyboard.
;n::ToolTip % (t := !t) ? "Bla" : "Ble"
;Down::
;if t := !t ? Send {Down Down} : Send {Down Up}
n=0 ; this isn't really needed, the invert of empty is 1
return
s::
n:=!n ; invert or reverse the prior value, 1 or 0 are the only choices
if n=1
Send {Down down} tooltip, thi i down
else
Send {Down up} tooltip, thi i up
return
SetBatchLines -1
#UseHook
Increment = 1 ; number of pixels to move mouse....gets multiplied depending on keypress length
MouseDelay = 0
w::
a::
s::
d::
xVal=
yVal=
If GetKeyState("CapsLock","T")
{
IncrementValue := Increment ; Set the Increment value (we change it)
; Infinite loop....breaks when key not pressed anymore
Loop,
{
;If (A_Index > IncrementValue * 15) and (IncrementValue < Increment * 5) ; Increase the Increment value depending on how long we held down the key
;IncrementValue := IncrementValue * 2
If GetKeyState("s", "P")
Send {Down down}
Else If GetKeyState("w", "P")
Send {Up down}
If !yVal
yVal := 0
If GetKeyState("a", "P")
Send {Left down}
Else If GetKeyState("d", "P")
Send {Right down}
If !xVal
xVal := 0
MouseMove, %xVal%, %yVal%,%MouseDelay%,R
KeyWait, %A_ThisHotKey%
Break
}
}
Else
Send % "{" . A_ThisHotKey . "}"
return
Esc::ExitApp
a::
Send {Left down} ; Hold down the left-arrow key.
return
j::
Send {Left up} ; Release the left-arrow key.
return
d::
Send {Right down} ; Hold down the Right-arrow key.
return
l::
Send {Right up} ; Release the Right-arrow key.
return
w::
Send {Up down} ; Hold down the Up-arrow key.
return
i::
Send {Up up} ; Release the Up-arrow key.
return
s::
Send {Down down} ; Hold down the Down-arrow key.
return
k::
Send {Down up} ; Release the Down-arrow key.
return
a:: ;These two likes also
If GetKeyState("CapsLock","p")
Send {Left Down} ;press down the Left key
else
Send a
Return
a Up::Send {Left Up}