AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Random time sleep and clicking a key

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Maciek
Guest





PostPosted: Wed Jan 13, 2010 4:16 pm    Post subject: Random time sleep and clicking a key Reply with quote

Hello!

Sorry, if my english is bad. I wrote this script:

Code:
Loop 999
{
Random, rand1, 6534, 8734

Send {F4 down}  ; Press down the up-arrow key.
Sleep rand1  ; Keep it down for one second.
Send {F4 up}  ; Release the up-arrow key

Random, rand2, 3465, 8945

Sleep rand2

Random, rand3, 3243, 5342

Send {F7 down}  ; Press down the up-arrow key.
Sleep rand3  ; Keep it down for one second.
Send {F7 up}  ; Release the up-arrow key

Random, rand4, 120243, 130342

Sleep rand4
}


I think it's simply and I hopa I don't have to write what it have to do. I was reading documentation, but it's still not working. Any idea?

Thank you in advance! Smile
Back to top
Peter



Joined: 30 Dec 2005
Posts: 448

PostPosted: Wed Jan 13, 2010 4:27 pm    Post subject: Reply with quote

Sleep expects a value, not just a "variable name". You have to use %%:
Code:
   Sleep %rand1%  ; Keep it down for one second.
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Jan 13, 2010 4:53 pm    Post subject: Reply with quote

Btw: The comment "Keep it down for one second." is wrong. The key is held down for about 6,5 to 8,7 secons, not one second.
Back to top
View user's profile Send private message
Maciek
Guest





PostPosted: Wed Jan 13, 2010 4:57 pm    Post subject: Reply with quote

Peter wrote:
Sleep expects a value, not just a "variable name". You have to use %%:
Code:
   Sleep %rand1%  ; Keep it down for one second.


Thank you Smile

I know that it's not for one second - I've got this part of code from this page Wink

But I still have problem. This part:

Code:
Send {F4 down}  ; Press down the up-arrow key.
Sleep %rand1%  ; Keep it down for some second.
Send {F4 up}  ; Release the up-arrow key


Isn't working right. It's only clicking F$ key one time. What's wrong with this? It's code, to generate a rand1:

Code:
Random, rand1, 6534, 8734
Back to top
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Jan 13, 2010 5:01 pm    Post subject: Reply with quote

Code:
Random, rand4, 120243, 130342

Sleep %rand4%

:

Did you really wait the whole 120 to 130 seconds if the F4-key was pressed a second time?
Back to top
View user's profile Send private message
Maciek
Guest





PostPosted: Wed Jan 13, 2010 5:04 pm    Post subject: Reply with quote

Yes, I need program to do:

click F4 for some seconds (random time, 6-8 sec)

wait some seconds

click F7 for some seconds (also random, 3-5 sec)

then wait about 120 seconds

ang do it again
Back to top
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Jan 13, 2010 5:15 pm    Post subject: Reply with quote

The script should do what you expect. How do you know if F4 key was pressed several times? Did you look into the key history of your running script?
Back to top
View user's profile Send private message
Maciek
Guest





PostPosted: Wed Jan 13, 2010 5:23 pm    Post subject: Reply with quote

I've tested it on notepad with F key (letter), and it write only one letter.
Back to top
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Jan 13, 2010 5:24 pm    Post subject: Reply with quote

It doesnt write letters but does click F-keys.
Please look in the key history of your script to see what happened.
Back to top
View user's profile Send private message
Maciek
Guest





PostPosted: Wed Jan 13, 2010 5:29 pm    Post subject: Reply with quote

I found a bug. In documentation is:

Quote:
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:

Loop 20
{
Send {Tab down} ; Auto-repeat consists of consecutive down-events (with no up-events).
Sleep 30 ; The number of milliseconds between keystrokes (or use SetKeyDelay).
}
Send {Tab up} ; Release the key.


Thank You for your help, and have a nice day Smile
Back to top
Maciek
Guest





PostPosted: Wed Jan 13, 2010 5:46 pm    Post subject: Reply with quote

Ohh, I'm back with a other question. Function Random is generating a new random number always when it's next time of a loop working? So it will generate other number for all 999 times of a loop?
Back to top
Peter



Joined: 30 Dec 2005
Posts: 448

PostPosted: Thu Jan 14, 2010 4:10 am    Post subject: Reply with quote

Maciek wrote:
I found a bug. In documentation is: ...
What's the bug? Did you try the example, and was it incorrect? (BTW, I had to search, but I found your quote on the Send page.)
Maciek wrote:
Function Random is generating a new random number always when it's next time of a loop working?
Yes, if it will start to generate every Loop a new random number
Maciek wrote:
So it will generate other number for all 999 times of a loop?
Not necessarily, the same number can be generated, the bottom line is, it can be any number (i.e. random) from your interval.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group