Sign in to follow this  
Followers 0
Joern

Hold Key down

8 posts in this topic

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

Share this post


Link to post
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:

Share this post


Link to post
Share on other sites

Opt("SendKeyDownDelay", 5000)  ;5 second delay
Send("w")
Opt("SendKeyDownDelay", 5)  ;reset to default when done


There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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"

Share this post


Link to post
Share on other sites

No one has a solution?

jb

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
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
Sign in to follow this  
Followers 0