Jump to content
Sign in to follow this  
Alex1

Make AutoIt hit "f1" and "f3" every set interval

Recommended Posts

Alex1

Hey, I'm trying to create a code which would click f3 every, say 10 seconds, and then hit f1 two seconds after hitting f3. This is for a game, and I'm not exactly sure where to start. Thanks a lot for your help.

~ Alex

Share this post


Link to post
Share on other sites
erebus

Start by reading the helpfile for the Send() and ControlSend() functions. Read the examples, try to write something by yourself and if you need more help, shoot.

Edited by erebus

Share this post


Link to post
Share on other sites
Alex1

I've coded in Flash before, and I'm not sure how similar this is to that. Do I need some sort of starter to tell it when to run? I'm not sure how to make it keep on running that action indefinitely.

Share this post


Link to post
Share on other sites
Alex1

Thanks jon, but how could i get that to keep repeating? Preferably, I'd like a constantly repeating script that makes f3 be pressed every 10 seconds, and f1 be pressed every 13 seconds

EDIT: Thanks for the help! It does repeat... I didn't realize. Thanks again I think I can modify it now how I would like.

Edited by Alex1

Share this post


Link to post
Share on other sites
Vindicator209

While...Wend

its a loop =P


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
The_Noob

i tend to use do... until 1=2 to do my loops... i should prolly learn while ... wend theyre (supposedly) better...

Perhaps have somthing like

$time = 1 ;declares $time as a variable

do ;starts the loop

if $time = 10 then send("keys here") ;do at 10 seconds

if $time = 13 then send("keys here") ;do at 13 seconds

if $time = 13 then $time = 1 ;every 13 seconds it will reset $time to 1

sleep(1000) ;pauses for one second.

$time = $time + 1 ;increases $time by one

until 1 = 2 ;will loop until 1 = 2... which never happens

Somthing like that, If you can code other languages you should be able to manipulate that to work. autoit wont read anything after ; so use them for notes.

hey since i brought it up... whats the advantages of using do loops vs using while loops?

#edit#

Heh i just realized that what i put does the same thing as what Jon did, but in like twice as many lines.

Duh... lol

Edited by The_Noob

Share this post


Link to post
Share on other sites
Vindicator209

=P

While...Wend isint necessarly better, but in about say 10000 times using it, you would save... about 10000 keypresses =P... though it is different if you use sCiTE's auto match... lol

but whats easier to explain?" 1 = infinite", or "1 never becomes 2 unless you declare it 2 within your loop"?

heh...lol

*ahem* off topic =P

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
herewasplato

...but whats easier to explain?" 1 = infinite", or "1 never becomes 2 unless you declare it 2 within your loop"?

While we are off topic:

An explanation of "1 = infinite" might draw some discussion from those that say that "1 = True" which might take quite a few words to explain.

While True
    Sleep(99)
WEnd

@The_Noob,

As for the difference between While/WEnd and Do/Until:

A While/WEnd loop may not execute the code inside the loop even once if the expression after the While is false.

A Do/Until loop will execute at least some of the code inside the loop at least once.

-MSP-

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Alex1

Could someone guide me to the best place to find good tutorials? The next thing I'd like to make is something that clicks down, types something in, presses enter, and does that every 1 minute or so (or alternating messages).

Share this post


Link to post
Share on other sites
Vindicator209

what game are you talking about?

well, start a timer:

$timer=TimerInit()

Then, somewhere in one of your loops, tell it to keep cheking it:

If TimerDiff($timer) > 60000 Then ;"greater than" because your loop likely wont be instantly looping

MouseClick("left") ;click

Send("message") ;type somthing in

Send("{enter}") ;press enter

$timer=TimerInit() ;Reset timer

EndIf ;endif

I havent exactly checked that yet but somewhere in that area =P


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
November

Hi,

And something like this?

AdlibEnable("F3", time in ms);define to run the func in ms 
AdlibEnable("F1", time in ms);define to run the func in ms 


;<script HERE>


func F3(); Press F3
    Send("{F3}")
EndFunc

Func F1(); Press F1
    Send("{F1}")
EndFunc

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
The_Noob

Hi,

And something like this?

AdlibEnable("F3", time in ms);define to run the func in ms 
AdlibEnable("F1", time in ms);define to run the func in ms 
;&lt;script HERE>
func F3(); Press F3
    Send("{F3}")
EndFunc

Func F1(); Press F1
    Send("{F1}")
EndFunc

Cheers

now that just totally confused me. But thanks for the information on while vs do is helpfull. I apprieate it. Thanks!

Share this post


Link to post
Share on other sites
Alex1

Thanks for the help guys... one more question, how do I randomize something? Like, make something happen every set interval, but within a 0-4 second time of that interval (and have the following action still come an equal time after?). Thanks :)

Share this post


Link to post
Share on other sites
PsaltyDS

$Delay = Random(250, 4000, 1)
AdlibEnable("F3", $Delay);define to run the func in ms
AdlibEnable("F1", $Delay);define to run the func in ms

Cheers!

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
herewasplato

Hi,

And something like this?

AdlibEnable("F3", time in ms);define to run the func in ms 
AdlibEnable("F1", time in ms);define to run the func in ms 


;<script HERE>


func F3(); Press F3
    Send("{F3}")
EndFunc

Func F1(); Press F1
    Send("{F1}")
EndFunc

Cheers

That won't quite work as you thought - thy this code and maybe you will see what I mean:
AdlibEnable("F3", 2000)
AdlibEnable("F1", 3000)

While 1
    Sleep(1111111111)
WEnd

Func F3()
    ToolTip("F3 at 2000")
    Sleep(1000)
    ToolTip("")
EndFunc   ;==>F3

Func F1()
    ToolTip("F1 at 3000")
    Sleep(1000)
    ToolTip("")
EndFunc   ;==>F1

Edit: typo

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

$Delay = Random(250, 4000, 1)
AdlibEnable("F3", $Delay);define to run the func in ms
AdlibEnable("F1", $Delay);define to run the func in ms

Cheers!

:)

Only one AdlibEnable will be active per script - right?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
PsaltyDS

Only one AdlibEnable will be active per script - right?

To quote the great philosopher Simpson: "DOH!" :)

You're right of course. I was only trying to demo saving a randomized integer for the delay and didn't think that through. It would also be redundant to set two AdLibEnable's for the same time base even if you could - just combine the functions.

:">


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
herewasplato

...how do I randomize something?

Run this and see what it teaches you:
While 1
    $slp = Random(500, 4000, 1)
    ToolTip("Random Sleep   " & $slp)
    Sleep($slp)
    ToolTip("Fixed Sleep   2000")
    Sleep(2000)
WEnd
After this, it is time for you to post some code... and then we can help correct any problems based on that code.

[size="1"][font="Arial"].[u].[/u][/font][/size]

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  

×