Jump to content

Hold Key down


Recommended Posts

I asked the question in another posting as well, but it was kinda missplaced.

I want to let AutoIt press down AND hold down a key. In the documentation you find something like the following:

Send('{w down}')

Sleep(5000)

Send('{w up}')

This always hits the key only 1 time even if I use SPACE instead. Any ideas?

I am using XP SP2 and downloaded AutoIt 2 days ago if that matters

jb

Link to comment
Share on other sites

That is correct. "w" or SPACE does not support a held down state at the API level. Your keyboard driver may allow continuous presses while the key is held down but that is the KB driver doing that. Only the modifier keys such as SHIFT, CTRL... support the DOWN and UP condition. If you want other keys to act like your KB does, then you may need to use a loop.

To get the held DOWN effect using a loop

Opt('SendKeyDelay', 50); Default speed
_Send('w', 5000)

Func _Send($text, $milliseconds)
    $time = TimerInit()
    Do
        Send($text)
    Until TimerDiff($time) > $milliseconds
EndFunc

:whistle:

Link to comment
Share on other sites

That is correct. "w" or SPACE does not support a held down state at the API level. Your keyboard driver may allow continuous presses while the key is held down but that is the KB driver doing that. Only the modifier keys such as SHIFT, CTRL... support the DOWN and UP condition. If you want other keys to act like your KB does, then you may need to use a loop.

To get the held DOWN effect using a loop

Opt('SendKeyDelay', 50); Default speed
_Send('w', 5000)

Func _Send($text, $milliseconds)
    $time = TimerInit()
    Do
        Send($text)
    Until TimerDiff($time) > $milliseconds
EndFunc

:whistle:

Just puzzled here... You are contradicting the help file on two things, what is the story here? I was trying to use something like this too, would like to understand it better.

1)

To hold a key down (generally only useful for games)

Send("{a down}") ;Holds the A key down

Send("{a up}") ;Releases the A key

Looks like you should be able to hold down a letter? What else would this mean?

2)

SendKeyDelay - <...> Time in milliseconds to pause (default=5)

I guess this might be a typo?

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Not to mention that _IsPressed (which uses API to get key state) returns true during that 5 second sleep between {w DOWN} and {w UP}.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Just puzzled here... You are contradicting the help file on two things, what is the story here? I was trying to use something like this too, would like to understand it better.

1)

Looks like you should be able to hold down a letter? What else would this mean?

2)

I guess this might be a typo?

I am not contradicting the help file. The help states a tip on a method for generally useful for games. That does not state the same use of a keyboard into a application such as notepad. If you try your shown code then try my example I have shown then you will see a difference. Testing my example compared to the help file example in notepad will show the difference.

1) It means that you can hold down a letter, but it will not repeat sending like a keyboard driver does normally. If software (such as a game) hooks the keyboard input then a different effect can happen with a key press. A concept comes to mind in games is analog and digital input which affects the operation of the keyboard.

2) The comment relates to the code usage. "Pause" affects the send speed, correct? :)

@Joern

Can you describe how you are using the Send function so others do not have to play the game of guessing a solution for you?

Link to comment
Share on other sites

  • 2 weeks later...

@Joern

Can you describe how you are using the Send function so others do not have to play the game of guessing a solution for you?

Sure I can but I thouhgt I already did. Maybe I miss the point.

For the controling of an avatar in a computer game I would like to press and hold down a specific key. I found something about this in the documentation. I tried this

Send('{w down}')

Sleep(5000)

Send('{w up}')

This does not work. It sends the key "w" here only once. Is this specific enough? If not, please let me know what infos would be needed.

Thanks for taking your time.

jb

Link to comment
Share on other sites

  • 12 years later...
On 7/23/2007 at 10:35 AM, Joern said:

I asked the question in another posting as well, but it was kinda missplaced.

 

I want to let AutoIt press down AND hold down a key. In the documentation you find something like the following:

 

Send('{w down}')

Sleep(5000)

Send('{w up}')

 

This always hits the key only 1 time even if I use SPACE instead. Any ideas?

 

I am using XP SP2 and downloaded AutoIt 2 days ago if that matters

 

jb

Greetings

Opt("SendKeyDownDelay", 5000)
Send('{RWIN DOWN}' & '{D DOWN}') ; in this example I used the RIGHT "windows" key down + "D" down (Minimize&Maximize active window)
Send ("{D UP}")
Send("{RWIN UP}")

:) Greetings

Link to comment
Share on other sites

  • Moderators

@Ghoul2020 did you notice this thread is 13 years old? I doubt the OP is hanging about hoping for an answer still. Please refrain from resurrecting ancient threads.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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