| View previous topic :: View next topic |
| Author |
Message |
superdave2k
Joined: 15 Oct 2004 Posts: 19
|
Posted: Sun Mar 05, 2006 4:57 pm Post subject: {Up down} and Sleep not keep the Up key down! |
|
|
Hi, I'm having a frustrating time simulating keeping an arrow key down. For example:
| Code: | #Persistent
Run, notepad
WinWaitActive, Untitled
Send, This is a test{ENTER 10}
Send {Up down} ; Press down the up-arrow key.
Sleep 5000 ; Keep it down for 5 seconds.
Send {Up up} ; Release the up-arrow key. |
I should see the cursor moving up to the top of the document since it should be holding the "up arrow" down for 5 seconds, but instead I only see it move one time.
I know the arrow is being held down by looking at the key history:
| Code: | 26 148 i d 0.01 Up
26 148 i u 5.01 Up |
So why aren't multiple "Up"s being simulated? I tried setting SetKeyDelay as suggested in the documentation but it has no effect.
The root of all this is the Making a Joystick Axis or POV Hat Send Keystrokes or Mouse Clicks section of the documentation. When I move the axis to the left, right, up, or down, I only get one simulated keystroke, when I really should be getting it "held down" until I move the joystick in a different direction.
Any idea what's going on here? Thanks... |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Sun Mar 05, 2006 6:54 pm Post subject: |
|
|
You need to manually simulate sending multiple key presses it seems (see my post at the bottom of this thread - you just need to change the sleep time/number of loops to get the right duration/repeat rate):
http://www.autohotkey.com/forum/viewtopic.php?t=8352 |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Mar 05, 2006 8:54 pm Post subject: |
|
|
| Thanks, sounds like I'm not the only one who has discovered this. Is this is a bug Chris, or a "known behavior"? This script from the documentation seems to indicate that left, right, up, and down arrows would be "held down" for the duration of the joystick move, but my testing shows this is clearly not the case. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10471
|
Posted: Sun Mar 05, 2006 9:12 pm Post subject: |
|
|
They are held down for the duration (the fact that they don't auto-repeat doesn't mean that they aren't down).
When you physically hold down a key for a while, it begins to auto-repeat because the driver or hardware says it should. By contrast, when you simulate the pressing down of a key, you get a single down event that keeps the key pressed down until the next up-event. Auto-repeat does not occur automatically (nor should it, because it would often be undesirable).
For another example script, see http://www.autohotkey.com/forum/viewtopic.php?t=4623 |
|
| Back to top |
|
 |
superdave2k
Joined: 15 Oct 2004 Posts: 19
|
Posted: Sun Mar 05, 2006 9:21 pm Post subject: |
|
|
OK, I understand now, thanks for the explanation Chris.
I'd like to put my vote in for an for Send {key down} that does auto-repeat internally. At the very least I think there should be a link to your script in the "Send, {key down}" documentation, as this seems to be a FAQ. |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Sun Mar 05, 2006 10:25 pm Post subject: |
|
|
| A link or the code and the brief explanation of why it doesn't repeat (so that users understand it isn't a bug/definiciency in AHK) would be good. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10471
|
Posted: Sun Mar 05, 2006 10:38 pm Post subject: |
|
|
I've added the following to the Send command page:
When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature). However, a Loop can be used to simulate auto-repeat. The following example sends 20 tab keystrokes:
| Code: | Loop 20
{
Send {Tab down} ; Auto-repeat consists of consecutive down-events (no up events).
Sleep 30 ; Adjust 30 to be the milliseconds between repeats.
}
Send {Tab up} |
Thanks for the suggestion. |
|
| Back to top |
|
 |
|