GUI Button function w/ autoit

01/01/2009 06:18 joshsta911#1
kk im a newbie at makin bots but heres the code i have now...
okay im a TOTAL newb at making stuff with autoit, so far i can only make simple things with clicking and what not...but i ran into a problem today. my bot creates a gui that instructs you on how to use the bot, what i need help with is how to create a hotkey that "Starts" the bot(the opposite of the exiting hotkey)
HotKeySet("^!x", "QuitProg")
Func QuitProg()
Exit
EndFunc
thats the exit hotkey that i got, but i was wondering if its possible to reverse it, and have a 2nd code like dat but it starts instead of exits....ty
01/01/2009 06:53 tao4229#2
From what I know of Win32, you have to handle the WM_COMMAND message for the button.(Windows will throw the message when the button is pushed) You'll have to assign the buttons ID and etc, and when you handle the WM_COMMAND message, check if it's the ID of the button and then execute your next code.

Don't ask how to do it in AutoIt though...


Edit:: Woah, you totally changed the first post....
I dunno anything about AutoIt so I guess ask swords or Hiyoal..
01/01/2009 08:29 joshsta911#3
rofl thanks for trying to help but you Totally lost me, it seems like it should be simple as hell becuase its just simply like this:
Person clicks the button then it should endswitch/closewindow and then move onto the next line..wich is the bot
01/01/2009 11:33 Hiyoal#4
Ok. So are you using another hotkey for this?! Or are you using the same hotkey?

Hiyoal
01/02/2009 03:01 joshsta911#5
no, ctrl+alt+x = exit script
and, ctrl+alt+z = start

i was thinking..is there a way that when you start the script from clicking it, it automatically pauses the script untill a hotkey is executed such as my "start"(ctr+alt+z)??
01/02/2009 03:12 Hiyoal#6
Until the GUI Pops up?!
Lets have a look at your script.

Hiyoal
01/02/2009 03:23 joshsta911#7
okay well since your here now and your wonderfull help i hope you wouldnt mind awnser another question at the same time :P
but heres my script

This script is to where a msg pops up with instructions, you minimize it and then press the hotkey CTRL+ALT+Z,(Idont have that part in yet becuase i dont know how to make it)
PHP Code:
HotKeySet("^!x""QuitProg")
Func QuitProg()
    Exit
EndFunc
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$ToxicFogLvler GUICreate("ToxicFogLvler"415170, -1, -1)
GUISetBkColor(0xC0C0C0)
$Label1 GUICtrlCreateLabel("This bot was created to level your ninja's Toxic Fog skill"0033320)
GUICtrlSetFont(-1104000"MS Sans Serif")
$Label2 GUICtrlCreateLabel("Created By Joshsta"2406414324)
GUICtrlSetFont(-1124008"MS Sans Serif")
$Label3 GUICtrlCreateLabel("To exit this bot simply hit CTRL+ALT+X"01627020)
GUICtrlSetFont(-1108000"MS Sans Serif")
$Label4 GUICtrlCreateLabel("Instructions:"0487320)
GUICtrlSetFont(-1104000"MS Sans Serif")
$Label5 GUICtrlCreateLabel("Sit = F3"0644017)
$Label6 GUICtrlCreateLabel("Have your toxic fog SKILL selected"08017117)
$Label7 GUICtrlCreateLabel("To start bot hit CTRL+ALT+Z"03216917)
GUICtrlSetFont(-188000"MS Sans Serif")
$Label8 GUICtrlCreateLabel("Make sure to minimize this window before starting!"2412834720)
GUICtrlSetFont(-1108004"MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg 
GUIGetMsg()
    Switch 
$nMsg
        
Case $GUI_EVENT_CLOSE
            
Exit

        Case 
$ToxicFogLvler
    
EndSwitch
WEnd 
and heres a simple question i have, its the same script just instead its worked with a button instead of a hotkey to start it..
PHP Code:
HotKeySet("^!x""QuitProg")
Func QuitProg()
    Exit
EndFunc
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\users\josh\desktop\botmakingshit\toxicfogbotcreatedbyjoshsta.kxf
$ToxicFogBot GUICreate("ToxicFogBot"349151, -1, -1)
GUISetBkColor(0xC8C8C8)
$Button1 GUICtrlCreateButton("Start"1204810557)
$Label1 GUICtrlCreateLabel("Created By Joshsta"21912812120)
GUICtrlSetFont(-1104000"MS Sans Serif")
$Label2 GUICtrlCreateLabel("The bot will start when you click Start.."0018617)
$Label3 GUICtrlCreateLabel("To exit the bot simply hit CTRT+ALT+X"01618817)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg 
GUIGetMsg()
    Switch 
$nMsg
        
Case $GUI_EVENT_CLOSE
            
Exit

        Case 
$Button1
    
EndSwitch
WEnd

While 1
MouseClick
("left" 57838821)
Sleep(1200)
MouseClick("right" 63545711)
Sleep(1200)
MouseClick("left" 69738721)
Send("{F3}")
Sleep(6000)
WEnd 
the problem with this bot is that when i click the button nothing happends, the "Window(gui)" that pops up dosnt go away when i click on $Button1 AkA Start...i dont know how to make it move onto the next part of the script thnx 4 ure help
01/02/2009 03:51 Hiyoal#8
Lol, Ok. Ill start off with the basics :p
Start off with #Include <> at the START OF YOUR SCRIPT!!!

A HotKeySet() Function does not need to be declared with a function underneath.

You can set however many hotkeys at the start of your script.

Quote:
Originally Posted by Hiyoal
#include <GUIConstants.au3>
HotKeySet("^!x", "QuitProg")
HotKeySet("^!z","StartProg")

#Region ### START Koda GUI section ### Form=
$ToxicFogLvler = GUICreate("ToxicFogLvler", 415, 170, -1, -1)
GUISetBkColor(0xC0C0C0)
$Label1 = GUICtrlCreateLabel("This bot was created to level your ninja's Toxic Fog skill", 0, 0, 333, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Created By Joshsta", 240, 64, 143, 24)
GUICtrlSetFont(-1, 12, 400, 8, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("To exit this bot simply hit CTRL+ALT+X", 0, 16, 270, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Instructions:", 0, 48, 73, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Sit = F3", 0, 64, 40, 17)
$Label6 = GUICtrlCreateLabel("Have your toxic fog SKILL selected", 0, 80, 171, 17)
$Label7 = GUICtrlCreateLabel("To start bot hit CTRL+ALT+Z", 0, 32, 169, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("Make sure to minimize this window before starting!", 24, 128, 347, 20)
GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func QuitProg()
Exit
EndFunc

Func StartProg()
;Put Your Function Here
EndFunc
Now, for the GUI.

You cannot have 2 While loops happening at once. The first one from top to bottom of the script will run first, so your:

Quote:
While 1
MouseClick()
jadslkfja;f
Wend
That will never happen unless the first WHile loop is exitted using Exitloop.


You dont have anything which the button does.

Switch looks at the variable $nMsg and checks to see if it changes.
If $button1 is clicked, $nMsg=$button1 sooo

Switch will move down to:
Case $button1

If their is one.

So, if you want those button clicks, you should do this.
Quote:
Originally Posted by Hiyoal
#include <GUIConstants.au3>
HotKeySet("^!x", "QuitProg")
HotKeySet("^!z","StartProg")

Global $checker=0 ;<--- DECLARE THIS!!

#Region ### START Koda GUI section ### Form=c:\users\josh\desktop\botmakingshit\toxicfogb otcreatedbyjoshsta.kxf
$ToxicFogBot = GUICreate("ToxicFogBot", 349, 151, -1, -1)
GUISetBkColor(0xC8C8C8)
$Button1 = GUICtrlCreateButton("Start", 120, 48, 105, 57)
$Label1 = GUICtrlCreateLabel("Created By Joshsta", 219, 128, 121, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("The bot will start when you click Start..", 0, 0, 186, 17)
$Label3 = GUICtrlCreateLabel("To exit the bot simply hit CTRT+ALT+X", 0, 16, 188, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
I have also declared the variable $checker=0 GLOBALLY so that it can be used throughout the whole script.

Then you should write the While function so the script stays alive:

Quote:
Originally Posted by Hiyoal
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button1
EndSwitch
WEnd
Next we add the function for clicking the button and we make our own Function which loops clicking.

Quote:
Originally Posted by Hiyoal
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button1
if $checker=0 then
$checker=1
elseif $checker=1 then
$checker=0
endif
EndSwitch

If $checker=1 Then
StartProg()
EndIf
WEnd

Func StartProg()
MouseClick("left" , 578, 388, 2, 1)
Sleep(1200)
MouseClick("right" , 635, 457, 1, 1)
Sleep(1200)
MouseClick("left" , 697, 387, 2, 1)
Send("{F3}")
Sleep(6000)
EndFunc
When the button is clicked, $checker is set to "1" and then the function "StartFunc" is called because in the:
While 1

Wend

loop, it checks to see if $checker=1 and will keep on running until the button on the GUI is pressed again.
Because, when $x=1 when button1 is pressed, it checks to see what $checker is and if it is 0 then it starts the bot, otherwise it see's whether $checker=1 and if it is then it makes it ="0" and will skip the:

If $checker=1 Then
StartProg()
EndIf

because $checker=0

Hope thats some insight.

Hiyoal
01/02/2009 04:20 joshsta911#9
oh snap, im not gonna lie i dont understand half of that. but from what i do understand, i understand what you did with the ctrl+alt+z, i also found out another way for this to work..
PHP Code:
Case $Button1
    GUISetState
(@SW_HIDE)
EndSwitch
WEnd 
so basically once they click start it just hides the gui and stops the switch, and they go on to pressing ctrl+alt+z to start the bot...! right? lol
01/02/2009 04:23 joshsta911#10
Btw is there a way that i can loop this function, after you click ctrl+alt+z
sorry if i wasted your time, id rather do it this way becuase i actually understand it sort of lol :x:handsdown:

PHP Code:
Func StartProg()
MouseClick("left" 57838821)
Sleep(1200)
MouseClick("right" 63545711)
Sleep(1200)
MouseClick("left" 69738721)
Send("{F3}")
Sleep(6000)
EndFunc 
01/02/2009 04:24 Hiyoal#11
Or, you can start the bot from clicking aswell.

PHP Code:
Case $button1
GUISetState
(@SW_HIDE)
StartProg()
EndSwitch
Wend 
Hiyoal

<edit>

Yes you can:

Declare Global $checker=0 at the start of your script

PHP Code:
Func StartProg()
if 
$checker=1 then
$checker
=0
elseif $checker=0 Then
$checker
=1
endIf
While 
$checker=1
MouseClick
("left" 57838821)
Sleep(1200)
MouseClick("right" 63545711)
Sleep(1200)
MouseClick("left" 69738721)
Send("{F3}")
Sleep(6000)
Wend
EndFunc 
This checks and see's whether $checker=1 or 0. If it equals to 0 then it makes $checker=1 and the while loop starts because $checker=1. When the hotkey is pressed again $checker=1 so it makes $checker=0 and the while stops, because While only runs when $checker=1.

Hiyoal
01/02/2009 04:46 joshsta911#12
oky fixed my hotkey situation Thanks alot Hiyoal, i spent a long time on this last nightl; just trying to get the gui function to work, it now works exacally how i want it, when i repost it ill make sure to give you credit :)
01/02/2009 05:55 Hiyoal#13
Np, glad 2 help. Hope i taught u something aswell :p

Hiyoal