Jump to content

Hold down input


Go to solution Solved by Nine,

Recommended Posts

Hello all,

 

I searched for the same thing and had trouble finding how to do it with AutoIt :

The subject dates from 2020 and is not resolved. I won't comment on the answers which shock me a little...

So I bring the answer to the subject and a new question.

 To be able to hold a key "{a down}" is not enough, in reality it only sends a key press event.

To do a repetition you must return this example:

HotKeySet("a","pressInput")
$stop= True

Func pressInput()
    $stop= Not $stop

    If ($stop) Then
        Send("{a up}")
    EndIf
EndFunc

While True
    If (not $stop) Then
        Send("{a down}")
    EndIf
    Sleep(10)
WEnd

Now, can someone please explain to me out of curiosity why it is necessary to return a "down" repeatedly? I tested this on several software programs, several games where you have to keep a key pressed and it works perfectly. So this system makes it possible to consider that the key is not released.

 

Thank :)

Link to comment
Share on other sites

  • Solution

It is the physical keyboard that sends multiple keys when you keep pressing a key.  It is not an interpretation of Windows.

But Windows knows if a key is pressed or not.  So in order to send multiple keys (like a keyboard would do), you need to send multiple down.  If you just send a key without the down option then up is also sent.

Here an illustration of it :

#include <WinAPISys.au3>
#include <Misc.au3>

Run("notepad")
WinWait("[CLASS:Notepad]")

Send("{a down}")
For $i = 1 To 20
  ConsoleWrite(_IsPressed("41") & @CRLF)
  Sleep(100)
  If $i = 10 Then Send("a")
Next

ConsoleWrite("======= next phase ========" & @CRLF)

Send("{a down}")
For $i = 1 To 20
  ConsoleWrite(_IsPressed("41") & @CRLF)
  Sleep(100)
  Send("{a down}")
Next

ConsoleWrite("======= final phase ========" & @CRLF)
Send("{a up}")
ConsoleWrite(_IsPressed("41") & @CRLF)

 

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...