some time ago I've written a SendInput() function (but it is not solely written by me) that I now have problems with. I did never use it in this constellation and thus never recognized the problems. The function has the purpose to introduce delay to the SendInput command.
However I am pretty sure there are no bugs left in my function and the problem might be AHK's fault. The problem occurs, when I keep the hotkey pressed and do not release it while the text is written.
Here is the code of the function (and others that are used in the first one):
Code: Select all
SendInput(keydelay:=10, string:="") {
if (keydelay < 0) {
SendInput, %string%
} else {
modifiers := []
Loop, Parse, string
{
if (!brace) {
modifier := RegExMatch(A_LoopField, "[\^!+#]", curr_modifier)
modifiers.Push(curr_modifier)
} if (modifier) {
continue
} else if (brace) {
if (IsNum(A_LoopField) && space) {
number .= A_LoopField
continue
} else if (A_LoopField = "}" && number > 0) {
curr_key := SubStr(curr_key, 1, StrLen(curr_key) - 1) "}"
Loop, %number% {
SendInput, % modifiers[1] modifiers[2] modifiers[3] modifiers[4] curr_key
Sleep(keydelay)
} modifiers := [], brace := space := number := false
} else if (A_LoopField = "}") {
curr_key .= "}"
SendInput, % modifiers[1] modifiers[2] modifiers[3] modifiers[4] curr_key
Sleep(keydelay), modifiers := [], brace := space := false
} else if (A_LoopField = A_Space && curr_key <> "{") {
curr_key .= A_LoopField
space := true
} else {
curr_key .= A_LoopField
continue
}
} else if (A_LoopField = "{") {
brace := A_Index
curr_key := "{"
continue
} else {
SendInput, % modifiers[1] modifiers[2] modifiers[3] modifiers[4] A_LoopField
Sleep(keydelay), modifiers := []
}
}
}
}
Sleep(delay) {
Sleep, delay
}
IsNum(var) {
if var is number
return true
return false
}
Code: Select all
!m:: SendInput(0, "This is a text to show the problem.")
Code: Select all
!m:: SendInput, This is a text to show the problem.
So basically the keys of the hotkey get pressed, although they should get blocked. Am I doing something wrong or is this a problem of AHK, as ist also happens with the command? Of course the Alt key gets pressed for every single letter/key by design in my function (a delay would not be possible otherwise), so it might be, that AHK is not able to block all those keypresses?
I am using Win10 64-bit, AHK Unicode 64-bit.
Edit: I have another example with the SendInput command that also generates Alt keystrokes.
Code: Select all
^!m:: SendInput, This is a text to show the problem.