Sign in to follow this  
Followers 0
NewUser01

Help me with beginner script

8 posts in this topic

Hi Im new and still learning to code AutoIT. I want to create a simple bot that send a key "W". I created a simple GUI and I want after I press "Run" button on the GUI, "W" key will be sent on the loop. But i cant get it to work. I really dont know what I am missing.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $iform = GUICreate("Bot", 180, 140)
Local $_Start = GUICtrlCreateGroup("Start", 8, 8)
Local $_Run = GUICtrlCreateButton("Run", 24, 24, 129)
Local $_Exit = GUICtrlCreateGroup("Exit", 8 ,72)
Local $_Close = GUICtrlCreateButton ("Close", 24,88,129)
GuiSetState(@SW_SHOW)

HotKeySet("{ESC}", "kill")

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


While 1
   $iMsg = GUIGetMsg()
   Switch $iMsg
   Case $GUI_EVENT_CLOSE
      Exit

   Case $_Close
      Exit

   Case $_Run
Func _Bot()
      Send("{W}")
      Sleep(2000)
EndFunc

EndSwitch
WEnd


Func kill()
   Exit
EndFunc

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Did you run it in SciTE4Autoit?

When run (F5) is pressed, you can see the errors in the console output

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Did you run it in SciTE4Autoit?

When run (F5) is pressed, you can see the errors in the console output

Yes i run it inside Scite. I only see a blue line with this one being the indication of error "ErrorStdOut". But other than that, i dont see anything else. The problem is I cant get it to work with the GUI. If I make a simple While loop, it works normally.

Edited by NewUser01

Share this post


Link to post
Share on other sites

Func _Bot() cannot be declared inside a Switch/Endswitch

Thanks, I remove the Func and it works as intended. Thank you for the prompt answer.

Share this post


Link to post
Share on other sites

Glad, that I could help.

BTW. Welcome to the forum.

And a little hint: Try to avoid the word 'bot'.

Read the forum rules (lower right corner in this window) and you'll understand why.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This seems a bit silly. The word itself is not specific to any particular application. The majority of example scripts could qualify. What is software automation if it isn't using some kind of robot? The forum rules are very specific about game automation, but the word bot is just a shorthand way of saying robot.

Edited by czardas

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