Read inputs (buffer) during blockinput

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Proxima
Posts: 2
Joined: 05 May 2024, 07:50

Read inputs (buffer) during blockinput

05 May 2024, 08:05

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!
User avatar
mikeyww
Posts: 27165
Joined: 09 Sep 2014, 18:38

Re: Read inputs (buffer) during blockinput

05 May 2024, 09:10

Welcome to this AutoHotkey forum!

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
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.
User avatar
Proxima
Posts: 2
Joined: 05 May 2024, 07:50

Re: Read inputs (buffer) during blockinput

05 May 2024, 10:49

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?
User avatar
boiler
Posts: 17180
Joined: 21 Dec 2014, 02:44

Re: Read inputs (buffer) during blockinput

05 May 2024, 12:19

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?
That’s because it’s not a # on the if, it’s the #If directive, which is fully documented.
User avatar
mikeyww
Posts: 27165
Joined: 09 Sep 2014, 18:38

Re: Read inputs (buffer) during blockinput

05 May 2024, 12:54

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 133 guests