Hello y'all!
I'd like a hotkey to execute a script sending inputs with sleeps inbetween. I'd like to end that sequence with a specific sendinput key, one that was pressed or held down during the execution of the sequence (limited to three possible keys, if that makes it more simple).
For example:
On Hotkey F1, the following text is being sent by SendInput with a sleep between the sentences: "Script initiated. The following key was pressed: ".
If the user held down/pressed the key '1' during the execution, it gets stored in a variable and sent at the end of the sequence, so that the result is: "Script initiated. The following key was pressed: 1".
The user should not be able to interrupt the sequence with the keypress, so that the pressed '1' only appears at the end of the text and not the middle of it.
My first thought was to disable the possibility to interrupt the sequence with blockinput, and get the keystates of keys pressed during the sequence with GetKeyState. However that appearently does not work for this usecase. Is there any way to read inputs during blockinput and store them, or is there a more suitable solution to this?
Dunno if what I wanted is even possible. I'm more familiar with v1 of ahk, please let me know if this specific case cannot be done with v1 but with v2 instead!
Read inputs (buffer) during blockinput
Re: Read inputs (buffer) during blockinput
Welcome to this AutoHotkey forum!
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
Code: Select all
#Requires AutoHotkey v1.1.33.11
F1::
hk := ""
on := True
Loop 5 {
Send % A_Index
Sleep 400
}
Send % "`nPressed: " hk
on := False
Return
#If (on && hk = "")
0::
b::
c::
hk := A_ThisHotkey
SoundBeep 1500
Return
#If
Re: Read inputs (buffer) during blockinput
Hello!
Thank you so much for your help. I tried to run your code and it somewhat worked, however there are still some quirks with it that I'm not able to iron out myself.
When running, it blocks the example keys '0', 'b' and 'c' during the sequence - but only once. If pressed twice, the keypress gets through during the sequence. It basically does exactly what I want it do if it would block every press during the sequence.
I tried to play with the (commented out?) second half of the script containing the if, but with that one I only manage to permanently block out the three keys when removing the # before the first if or when putting the code in brackets below the if ({ }).
The documentation does not specify a # on the if (https://www.autohotkey.com/docs/v1/lib/IfExpression.htm), maybe I'm not understanding it correctly?
Thank you so much for your help. I tried to run your code and it somewhat worked, however there are still some quirks with it that I'm not able to iron out myself.
When running, it blocks the example keys '0', 'b' and 'c' during the sequence - but only once. If pressed twice, the keypress gets through during the sequence. It basically does exactly what I want it do if it would block every press during the sequence.
I tried to play with the (commented out?) second half of the script containing the if, but with that one I only manage to permanently block out the three keys when removing the # before the first if or when putting the code in brackets below the if ({ }).
The documentation does not specify a # on the if (https://www.autohotkey.com/docs/v1/lib/IfExpression.htm), maybe I'm not understanding it correctly?
Re: Read inputs (buffer) during blockinput
That’s because it’s not a # on the if, it’s the #If directive, which is fully documented.Proxima wrote: ↑ The documentation does not specify a # on the if (https://www.autohotkey.com/docs/v1/lib/IfExpression.htm), maybe I'm not understanding it correctly?
Re: Read inputs (buffer) during blockinput
More....
Code: Select all
#Requires AutoHotkey v1.1.33.11
F1::
hk := ""
on := True
Loop 5 {
Send % A_Index
Sleep 400
}
Send % "`nPressed: " hk
on := False
Return
#If on
0::
b::
c::
hk .= A_ThisHotkey
SoundBeep 1500
Return
#If
Who is online
Users browsing this forum: anonymous_user, Google [Bot] and 128 guests