Jump to content

Newbie help needed


Recommended Posts

I'm totally new to writing scripts. After reading the help files etc.. I felt that I could write a basic script. However, I get errors everytime :/. Could someone please give me an example of a very basic script? I just need it to press one key (lets say... 5) and press it like every 5 seconds for a continuous loop. It would be nice if someone could show me how to setup a hotkey in it to toggle on/off the script. Some thing like F8 would be nice. I think if anyone can help by showing me a script that will do something like this, I can figure out where my mistake is, and then learn to write slightly more complicated things. Thanks in advance for helping an ignorant noobie :)

Edited by smokinbudz
Link to comment
Share on other sites

Well I tried this for typing ` every ten milliseconds... but it doesn't work. I know I'm doing something wrong on line 1, but I have no idea what. Once again, I consider myself computer savvy, but I don't know jack about scripts. Trying to learn. Thanks to anyone who can help. There may be other mistakes here, if anyone can coreect for me it will be greatly appreciated

Global

HotKeySet("{HOME}", "TogglePause")

HotKeySet("{END}", "Terminate")

While 1

Sleep(100)

WEnd

Func TogglePause()

= NOT

While

sleep(10)

send("`")

WEnd

EndFunc

Func Terminate()

Exit 0

EndFunc

Edited by smokinbudz
Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("example", 300, 50, -1, -1)
$Button_1 = GUICtrlCreateButton ("Start (use f8 to pause and start again)",  0, 0, 300, 50)
GUISetState ()
$pause = 1
HotKeySet("{F8}", "_Pause")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Button_1
            AdlibEnable("_Press", 5000)
    EndSelect
Wend

Func _Press()
    If $pause = 1 Then
        Send("5")
        MsgBox(0, "test", "5 was sent");for testing purposes-remove
    EndIf
EndFunc

Func _Pause()
    If $pause = 1 Then
        $pause = -1
        AdlibDisable()
    Else
        $pause = 1
        AdlibEnable("_Press", 5000)
    EndIf
EndFunc

Link to comment
Share on other sites

Holy crap. I really dont understand why what i had wasn't working though. I see in your example, you setup an example box to come up. That's neat. Hmm so is what I had completely off track? Or, is there a simple mistake here, that would make what I have functional? I'm new and totally ignorant so this example just confused me if anything lol :)

Edited by smokinbudz
Link to comment
Share on other sites

Based off of the OP's code, mostly you had the Send("`") in the wrong function, it needs to be in your while statement as shown below. There are many ways to code things, you were not that far off.

Global $Paused
HotKeySet("{HOME}", "TogglePause")
HotKeySet("{END}", "Terminate")


While 1
Sleep(2000)
Send("`")
WEnd


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('"Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Edit: Grammar

Edited by schilbiz
Link to comment
Share on other sites

Don't know if it matters... but,

based off schilbiz's code (modifed time/added gui), this gives a visual example (hopefully not too confusing) of what's going on in the script.

#include <GUIConstants.au3>
;comments start with ";" and are in green

$Gui=GUICreate("example", 300, 300, -1, -1, "", $WS_EX_TOOLWINDOW)  ;<<<create gui
GUISetFont(20)  ;<<<sets gui font

$editbox = GUICtrlCreateEdit ("",  0, 0, 295, 275)  ;<<<create edit box to write the "`" every 5 seconds

GUISetState ()  ;<<<show gui

Global $Paused  ;<<<makes $Paused available throughout script
HotKeySet("{HOME}", "TogglePause")  ;<<<set hot key to pause or resume
HotKeySet("{END}", "Terminate") ;<<<set hot key to exit script

While 1 ;<<<start loop to countdown to 0... set title of window... and set data in $editbox
$i = 5
    Do  ;<<<start countdown
        WinSetTitle($Gui, "", $i)   ;<<<set title of window
        Sleep(1000) ;<<<wait 1 second
        $i = $i -1  ;<<<decrease time variable
    Until $i = -1   ;<<<continue loop or end countdown
Send("`")   ;<<<write "`" to $editbox
WEnd

Func TogglePause()  ;<<<pause it... resume, by hitting HOME
    $Paused = NOT $Paused
    While $Paused
        Sleep(100)
        ToolTip('"Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()    ;<<<exit by hitting END
    Exit 0
EndFunc
Edited by The Ape
Link to comment
Share on other sites

Well I tried this for typing ` every ten milliseconds... but it doesn't work. I know I'm doing something wrong on line 1, but I have no idea what. Once again, I consider myself computer savvy, but I don't know jack about scripts. Trying to learn. Thanks to anyone who can help. There may be other mistakes here, if anyone can coreect for me it will be greatly appreciated

Global

HotKeySet("{HOME}", "TogglePause")

HotKeySet("{END}", "Terminate")

While 1

Sleep(100)

WEnd

Func TogglePause()

= NOT

While

sleep(10)

send("`")

WEnd

EndFunc

Func Terminate()

Exit 0

EndFunc

Provided you had a Global variable set and a few other things.

Your code would have no output, just a continuous Sleep(100), till you went to hit "Pause" then you would get a continuous stream of `````````````````` like you were holding the "`" key down, until you hit "Pause" again, which would go back into the loop While 1 which would just sleep.

So in a bass ackwards way it would work .. :)

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...