Jump to content

func help plz :)


Recommended Posts

Hello,

I'm designing a little program for friends.

Basically I want this code to allow them to input information into an input box and then by pressing a hotkey, having that information spat out into a text field specific to a certain program.

This is the meat of the code.

Global $var1 = inputbox("title", "enter your stuff")
Sleep (500)
Global $var2 = inputbox("title", "enter your other stuff")

HotKeySet("{F2}","input")
HotKeySet("{F3}","exitapp")

func input()
    HotKeySet("{F2}")
    Tooltip("Your info was sent", 0, 0)
        send($var1)
        send("{tab}")
        send($var2)
        send("{enter}")
                sleep(2000)
    EndFunc

    func exitapp()
        HotKeySet("{F3}")
        Exit
    EndFunc

This will be my third day with Autoit and I'm still settling into it :)

Me and my friend spent a night trying different things to get the script to follow through but it always terminates after the input boxes.

We hypothesized that it needed a loop to keep the script alive. But everything we tried gave an error. :)

Tell me what to do guys, thanks!

Link to comment
Share on other sites

Global $var1 = inputbox("title", "enter your stuff")
Sleep (500)
Global $var2 = inputbox("title", "enter your other stuff")

HotKeySet("{F2}","input")
HotKeySet("{F3}","exitapp")
while 1
sleep (100)
wend
func input()
    HotKeySet("{F2}")
    Tooltip("Your info was sent", 0, 0)
    send($var1)
    send("{tab}")
    send($var2)
    send("{enter}")
    sleep(2000)
EndFunc

func exitapp()
    HotKeySet("{F3}")
    Exit
EndFunc

try that? *NOT TESTED*

Edited by CodyBarrett
Link to comment
Share on other sites

That will work. What was wrong with your script is that it doesn't linger.

This is the only part the script is set to run:

Global $var1 = inputbox("title", "enter your stuff")
Sleep (500)
Global $var2 = inputbox("title", "enter your other stuff")
HotKeySet("{F2}","input")
HotKeySet("{F3}","exitapp")

The script automatically ends and exits after the second HotKeySet. Adding a very long sleep or an infinite loop at the end will prevent your script from terminating. If using an infinite loop, inserting a Sleep(100) inside prevents your script from hogging the CPU resources while it lingers. So the infinite loop would look like so:

While 1 ;always true so loop never ends
    Sleep(100)
WEnd

These are just function definitions and will not be run unless they are called:

Func input()
    HotKeySet("{F2}")
    Tooltip("Your info was sent", 0, 0)
    send($var1)
    send("{tab}")
    send($var2)
    send("{enter}")
    sleep(2000)
EndFunc

Func exitapp()
    HotKeySet("{F3}")
    Exit
EndFunc

Note: You do realize that you are removing the hot key for F2 when you press F2 the first time, meaning that your hot key will only be usable once.

Link to comment
Share on other sites

Wow, lol I don't know why that hotkeyset was in the function o.0 blah... thanks

Alright, It works amazing now, the only problem that remains is my tooltip hangs around forever... I would like it to end after a period of time :)

I feel like I'm cheating. You guys are good. lol

This is my code so far:

Global $var1 = inputbox("title", "put stuff here")
Sleep (500)
Global $var2 = inputbox("title", "put more stuff here")

HotKeySet("{F2}","input")
HotKeySet("{F3}","exitapp")

While 1
    sleep(100)
    WEnd

func input()
    Tooltip("Stuff is happening", 150, 0)
        send($var1)
        send("{tab}")
        send($var2)
        send("{enter}")
sleep(500)
    EndFunc

    func exitapp()
        Exit
    EndFunc
Link to comment
Share on other sites

From the help file regarding ToolTip, in the Remarks section:

A Tooltip will appear until the script terminates or ToolTip("") is called.

So you can just show your tooltip then sleep for a bit then call ToolTip("").

Edited by omikron48
Link to comment
Share on other sites

How about this:

You can change the 3000 which is 3 seconds to what ever value you want.

Global $var1 = inputbox("title", "enter your stuff")
Sleep (500)
Global $var2 = inputbox("title", "enter your other stuff")

HotKeySet("{F2}","input")
HotKeySet("{F3}","exitapp")
while 1
sleep (100)
wend
func input()
    HotKeySet("{F2}")
    Tooltip("Your info was sent", 0, 0)
    AdlibEnable("KillToolTip",3000)
    send($var1)
    send("{tab}")
    send($var2)
    send("{enter}")
    sleep(2000)
EndFunc

func exitapp()
    HotKeySet("{F3}")
    Exit
EndFunc

Func KillToolTip()
ToolTip("")
AdlibDisable()
EndFunc
Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Everything is shiny and perfect! I will try more advanced scripting later on. This was just a test to see how versital this code is.

I learned a great deal from this, thank you all :)

I hope to help others like this someday, but for now I'm going to squabble in my newbiness :P

And that help file is pretty :) thanks for bringing that to my attention

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...