smokinbudz Posted December 3, 2007 Share Posted December 3, 2007 (edited) 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 December 3, 2007 by smokinbudz Link to comment Share on other sites More sharing options...
The Ape Posted December 3, 2007 Share Posted December 3, 2007 I'll give you my example... if you give me yours first. FixJaw.comTriad-Art.com Link to comment Share on other sites More sharing options...
smokinbudz Posted December 3, 2007 Author Share Posted December 3, 2007 (edited) 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 December 3, 2007 by smokinbudz Link to comment Share on other sites More sharing options...
The Ape Posted December 3, 2007 Share Posted December 3, 2007 #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 FixJaw.comTriad-Art.com Link to comment Share on other sites More sharing options...
smokinbudz Posted December 3, 2007 Author Share Posted December 3, 2007 (edited) 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 December 3, 2007 by smokinbudz Link to comment Share on other sites More sharing options...
schilbiz Posted December 3, 2007 Share Posted December 3, 2007 (edited) 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 December 3, 2007 by schilbiz Link to comment Share on other sites More sharing options...
The Ape Posted December 3, 2007 Share Posted December 3, 2007 (edited) 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 December 3, 2007 by The Ape FixJaw.comTriad-Art.com Link to comment Share on other sites More sharing options...
schilbiz Posted December 3, 2007 Share Posted December 3, 2007 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 appreciatedGlobal HotKeySet("{HOME}", "TogglePause")HotKeySet("{END}", "Terminate")While 1 Sleep(100)WEndFunc TogglePause() = NOT While sleep(10) send("`") WEndEndFuncFunc Terminate() Exit 0EndFuncProvided 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 More sharing options...
smokinbudz Posted December 4, 2007 Author Share Posted December 4, 2007 ty all very much Link to comment Share on other sites More sharing options...
DirtDBaK Posted December 4, 2007 Share Posted December 4, 2007 Hey btw newbies welcome I'm fairly new to the froum, but im pretty advanced in AutoIT.... Anyways look in example scripts for examples... -OR- tell me wut you want the example script to do [center][/center] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now