Sign in to follow this  
Followers 0
LatecomerX

Problem getting AutoIt to hold down a key

4 posts in this topic

I have read the docs and browsed through more than a dozen of previously created topics, but I still can't find the answer to my problem I'm facing here. Ok here's the sample code I'm trying to execute:

CODE
Send("{LSHIFT down}")

Send("{w down}")

Sleep(5000)

Send("{w up}")

Send("{LSHIFT up}")

The only output I get is a single 'W', as though the key was not held at all, when I am expecting something like 'WWWWWWWWWWWWWWWWWWWWWWWWWWWWW'. But strangely, it is still capitalized because the Shift key is down when the 'w' key was sent. When I commented out the LSHIFT lines, I get a single 'w'. So what could be causing the issue for me here? (I'm using the stable Nov 2007 version of AutoIt).

Share this post


Link to post
Share on other sites



I have read the docs and browsed through more than a dozen of previously created topics, but I still can't find the answer to my problem I'm facing here. Ok here's the sample code I'm trying to execute:

CODE
Send("{LSHIFT down}")

Send("{w down}")

Sleep(5000)

Send("{w up}")

Send("{LSHIFT up}")

The only output I get is a single 'W', as though the key was not held at all, when I am expecting something like 'WWWWWWWWWWWWWWWWWWWWWWWWWWWWW'. But strangely, it is still capitalized because the Shift key is down when the 'w' key was sent. When I commented out the LSHIFT lines, I get a single 'w'. So what could be causing the issue for me here? (I'm using the stable Nov 2007 version of AutoIt).
Send() and physically holding down a key are not quite the same Send() does not have auto repeat.

This will achieve your desired result

Send("{LSHIFT down}")
$begin = TimerInit()
Do  
Send("w")
Until TimerDiff($begin) > 5000
Send("{LSHIFT up}")

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Oh ok, now I understand Send() better. Thanks for your help.

I have another question. Is there a way to send DOWN/UP modifiers with ControlSend? The docs mention something about SendAttachMode which disables them for ControlSend:

"Specifies if AutoIt attaches input threads when using Send() function. When not attaching (default mode=0) detecting the state of capslock/scrolllock and numlock can be unreliable under NT4. However, when you specify attach mode=1 the Send("{... down/up}") syntax will not work and there may be problems with sending keys to "hung" windows. ControlSend() ALWAYS attaches and is not affected by this mode.

0 = don't attach (default)

1 = attach"

- http://www.autoitscript.com/autoit3/docs/f...#SendAttachmode

Share this post


Link to post
Share on other sites

Any help from the experts and long-time users here?

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