Sign in to follow this  
Followers 0
moth

New to autoit

4 posts in this topic

Hey guys! I go to uni learning c++ and i am trying out this program since it seems to be pretty handy and not as complicated as programming in c++.

HotKeySet("^{F1}", "Basic")
HotKeySet("^{F1}", "Advanced")

WinWaitActive("Windowname","","2000")

Sleep(2000)

Basic()
Advanced()

Func Basic()
    SendKeys "{F1},{F2},{F3},{F4},{F5},{F6},{F7}"

EndFunc

Func Advanced() 
    SendKeys "{F1},{F2},{F3},{F4},{F5},{F6},{F7}"

EndFunc

What i am trying to do here is for example , when i press ctrl+F1 , which is what i have learned is ("^{F1}" ?, the program should send the keys {F1},{F2},{F3},{F4},{F5},{F6},{F7}.

My questions now are:

If i want it to send a string when i press ctrl+f1, it it just send "thisismymessage" ?

How do i make it wait , so that i can press ctrl+f1 , and it runs the basic function and goes back to "idle" , would that be like a if loop in c++?

How do you guys test ur scripts to see if they are working? I would appreciate some help, only this little script took me over 1h to write and i would appreciate if somone could help me out further with this, add my mail or something like that since it takes long time to get help on the forums.

Thanks in advance

Moth

Share this post


Link to post
Share on other sites



Hello Moth,

First, Welcome to the AutoIt Forums :graduated:

Give this a whirl, I commented behind my changes, to help you understand what I did.

HotKeySet("^{F1}", "Basic")
HotKeySet("{ESC}","Terminate")

WinWaitActive("Windowname","","2000")

While 1 ;this will loop continuously until you press Escape, or Ctrl+{F1}
    Sleep(10); this sleep will help from hogging your cpu.
WEnd

Func Basic()
    Send("{F1}{F2}{F3}{F4}{F5}{F6}{F7}") ;This is the proper way to send keys or strings.
EndFuncFunc Terminate()
    Exit 0
EndFunc

I hope this helps :(

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

haha realm , you made it look so easy! Thanks alot for the welcoming and for the help! I see now how this is done. What kind of loop would i use to make several entries then? I was looking now at a case loop but i dont know how to contruct it, i was trying to make it like this. I hope you get what i mean ^^ Like the program jsut runs the script once and then waits for the next entry.

Hope you didnt mind i used your code now! Looked so much better then mine!

HotKeySet("^{F1}", "Basic")
HotKeySet("^{F2}", "Advanced")
HotKeySet("{ESC}","Terminate")

WinWaitActive("Windowname","","2000")

While 1 ;this will loop continuously until you press Escape, or Ctrl+{F1}
    Sleep(10); this sleep will help from hogging your cpu.
WEnd

Func Basic()
    Send("{F1}{F2}{F3}{F4}") ;This is the proper way to send keys or strings.
Func Advanced()
    Send("{F5}{F6}{F7}") ;This is the proper way to send keys or strings.

EndFuncFunc Terminate()
    Exit 0
EndFunc

Now , when i press ctrl+1 i goes into function Basic and sends F1 F2 F3 F4 for example, and then goes to an "idle" where i can press either ctr+f1 for the basic function again or ctrl+f2 for the Advanced one?

is it as simple as binding it to hotkeys?

HotKeySet("^{F1}", "Basic")

HotKeySet("^{F2}", "Advanced")

How did you guys learn to handle this program, is there a white paper with all scripts etc for this program? ^^, Would appreciate a link

Hello Moth,

First, Welcome to the AutoIt Forums :graduated:

Give this a whirl, I commented behind my changes, to help you understand what I did.

HotKeySet("^{F1}", "Basic")
HotKeySet("{ESC}","Terminate")

WinWaitActive("Windowname","","2000")

While 1 ;this will loop continuously until you press Escape, or Ctrl+{F1}
    Sleep(10); this sleep will help from hogging your cpu.
WEnd

Func Basic()
    Send("{F1}{F2}{F3}{F4}{F5}{F6}{F7}") ;This is the proper way to send keys or strings.
EndFuncFunc Terminate()
    Exit 0
EndFunc

I hope this helps :(

Realm

Edited by moth

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

moth,

You can keep the While Loop. No need for a Switch or Select loop, well depending on what your intentions truly are. What happens in this script is that your script will run until it hits the While Loop, where it will continousely loop until your press a HotkeySet, or you may set other conditions for the loop to check on its own. Whenever you press a hotkey, it pauses the script where it's at, performs the Function that is called by the HotKey. Once that function has completed, the script will resume where it left off, in this case back inside the While loop, continously looping and waiting for more HotKey commands.

On another Note, Whenever a Function is called from within your script, the script will pause there, Run the called Function, then return to where it left off.

HotKeySet("^{F1}", "Basic")
HotKeySet("^{F2}","Advanced")
HotKeySet("{ESC}","Terminate")

WinWaitActive("Windowname","","2000")

;run some initial code

While 1 
    Sleep(10)
WEnd

Func Basic()
    Send("{F1}{F2}{F3}{F4}{F5}{F6}{F7}")
EndFunc

Func Advanced()
    Send("{F5}{F6}{F7}")
EndFunc

Func Terminate() ; Fix this, my fault, I did'nt catch the error in my first post
    Exit 0
EndFunc

I hope this helps to clear this up more. In the help file there is a tutorial Folder, reading through that should give you a good grasp on the basics of AutoIt, and with your prior experiences, it shouldn't take long at all to grasp this, some what similar to C++, just a different Structure.

Realm

Edit: Read the helpfile about HotKeySet(), and always check your system and current applications that will be running while your script is, incase they call the same HotKey you are attempting to assign, it could lead to script errors or worse.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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