Sign in to follow this  
Followers 0
gui529

Hold Down Key

12 posts in this topic

I want it to hold space down for 3 seconds but it only sends space once. what is wrong with this script?

Func Pickup()
    ControlSend($GameTitle, "", "", "{SPACE down}")
    sleep(3000)
    ControlSend($GameTitle, "", "", "{SPACE up}")
endfunc

Share this post


Link to post
Share on other sites



nothing really happens with that code. i tried run it and it just closes :[

Share this post


Link to post
Share on other sites

This is another question. Did your code worked in first place? You need to specify the ClassNN to successfully send keystrokes to the control.

Share this post


Link to post
Share on other sites

In response to your first post, that is the behavior you should expect. Holding a key and letting it go produces one character. If you want to repeat it, you have to add messages for repeating.

Share this post


Link to post
Share on other sites

This is another question. Did your code worked in first place? You need to specify the ClassNN to successfully send keystrokes to the control.

Yes, my first code did work but it only sends 1 character. As if its presing it once and not really holding it.

In response to your first post, that is the behavior you should expect. Holding a key and letting it go produces one character. If you want to repeat it, you have to add messages for repeating.

I see...so in order to do what i want i would have to play with sleeps and more sends?? or a loop?

Share this post


Link to post
Share on other sites

If your code worked for you then I believe it's something about SendKeyDownDelay option. Try to play with different values like 100 or 250 ms.

Share this post


Link to post
Share on other sites

SendKeyDownDelay is when you are sending regular keys, not key ups or downs.

To repeat a key, you have to send a key repeat event. That will require you to learn window messages.

Share this post


Link to post
Share on other sites

Correct me if I'm wrong:

Opt('SendKeyDownDelay', 20)

Run('notepad')
WinWaitActive('Untitled')
Dim $hWnd = WinGetHandle('Untitled')

Dim $iInit = TimerInit()
Do
    ControlSend($hWnd, '', 'Edit1', '{a down}')
Until TimerDiff($iInit) > 2000
ControlSend($hWnd, '', 'Edit1', '{a up}')

ControlSend($hWnd, '', 'Edit1', '{ENTER}')

Opt('SendKeyDownDelay', 100)

$iInit = TimerInit()
Do
    ControlSend($hWnd, '', 'Edit1', '{a down}')
Until TimerDiff($iInit) > 2000
ControlSend($hWnd, '', 'Edit1', '{a up}')

Share this post


Link to post
Share on other sites

SendKeyDownDelay is the amount of time to wait before sending the key up code when just sending plain characters. Like Send("a") will use SendKeyDownDelay.

Share this post


Link to post
Share on other sites

Ok, I get the picture, so SendInput is much reliable method but I can't update to SP3 =$ otherwise my router won't like me anymore ;] but thanks for correcting me.

Share this post


Link to post
Share on other sites

That doesn't make any sense. What does the service pack have anything to do with SendInput? And when did SendInput even enter the conversation?

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