Jump to content

Text input/Send with GUI - Help needed!


Recommended Posts

Alright, so I've done some tutorials in AutoIt, and the first script I made with *no* tutorial was this. It basically just sends some text in a loop and has a few hotkeys/msg boxes. And, it works - so I was impressed :D

Global $counter=0
$i = 0
Startup()

Func Startup()
    $msgbox=Msgbox(4, "Startup", "Press Yes to open the auto-tweeter or press No to exit. Whilst in the auto-tweeter, pressing INSERT will commence tweeting within 3 seconds, and pressing END will exit the auto-tweeter.")
    If $msgbox=6 Then
        Menu()
    EndIf
    If $msgbox=7 Then
        Exit
    EndIf
EndFunc

Func Menu()
    $counter=1
    While $counter=1
        HotKeySet("{INSERT}", "Tweet")
        HotKeySet("{END}", "Startup")
    WEnd
EndFunc

    
Func Tweet()    
    Sleep(3000)
    While $i <= 10
        Sleep(100)
        Send("Auto-tweeting program works!")
        $getpos=MouseGetPos()
        MouseMove(809, 270, 0)
        MouseClick("Left", 809, 270, 1) 
        Sleep(1000)
        MouseMove(446, 225, 0)
        MouseClick("Left", 446, 225, 1) 
        $i = $i + 1
    WEnd
    $msgbox=Msgbox(4, "Completed", "Auto-tweeting finished. Press Yes to exit.")
    If $msgbox=6 Then
        Exit
    EndIf
EndFunc

Next I looked at some stuff about KODA and GUIs, and managed to make this thing, which I hoped would make whatever you type in the boxes be what it sends etc. (Ignore the ;'d script at the end). The GUI loads fine, it just doesn't actually do anything and closes.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=d:\autoit\koda\forms\autotweeter v1.kxf
$Form1_1 = GUICreate("Form1", 454, 141, 190, 117)
$v1 = GUICtrlCreateLabel("v1", 432, 120, 16, 17)
$text = GUICtrlCreateInput("Enter your text here (140 chars max)", 8, 56, 441, 21)
$ok = GUICtrlCreateButton("Ok", 368, 80, 81, 25, $WS_GROUP)
$times = GUICtrlCreateInput("Number of times to tweet", 8, 80, 169, 21)
$note = GUICtrlCreateLabel("Please note there is a limit to how many times you can tweet in an hour.", 8, 120, 339, 17)
$delay = GUICtrlCreateInput("Delay between tweets (ms)", 184, 80, 177, 21)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Tim again!\My Documents\My Pictures\at.JPG", 8, 8, 209, 41, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

Global $counter=0
$i = 0


Func Startup()
;$counter=1
    While $counter=1
        HotKeySet("{INSERT}", "Tweet")
        HotKeySet("{END}", "Startup")
    WEnd
EndFunc


Func Tweet()
    Sleep(3000)
    While $i <= $times
        Sleep($delay)
        Send($text)
        $getpos=MouseGetPos()
        MouseMove(600, 300, 0)
        MouseClick("Left", 600, 300, 0)
        Sleep($delay)
        MouseMove(200, 250, 0)
        MouseClick("Left", 200, 250, 0)
        $i = $i + 1
    WEnd
;$msgbox=Msgbox(4, "Completed", "Auto-tweeting finished. Press Yes to exit.")
;If $msgbox=6 Then
;   Exit
;EndIf
EndFunc

Unfortunately it didn't work... so I kept trying. Then I tried making the variables for $text etc. Global - probably a terrible idea but I don't really know much so I thought I'd give it a go. This made it send text, but only to send the number 4 seven times, rather than what I typed. Script here:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\AutoIt\KODA\Forms\autotweeter v1 v2.kxf
$Form1_1 = GUICreate("Form1", 452, 141, 198, 157)
$v1 = GUICtrlCreateLabel("v1", 432, 120, 16, 17)
Global $text = GUICtrlCreateInput("Enter your text here (140 chars max)", 8, 56, 441, 21)
$ok = GUICtrlCreateButton("Ok", 368, 80, 81, 25, $WS_GROUP)
$note = GUICtrlCreateLabel("Please note there is a limit to how many times you can tweet in an hour.", 8, 120, 339, 17)
Global $delay = GUICtrlCreateInput("Delay between tweets (ms)", 184, 80, 177, 21)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Tim again!\My Documents\My Pictures\at.JPG", 8, 8, 209, 41, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
Global $times = GUICtrlCreateCombo("Number of times to tweet", 8, 80, 169, 25)
GUICtrlSetData(-1, "5|10|15|20|25|30|35|40|45|50")
$warn = GUICtrlCreateLabel("Starts after 3 seconds from clicking Ok", 224, 8, 186, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $i=0

Func Tweet()
    Sleep(3000)
    While $i <= $times
        Sleep($delay)
        Send($text)
        $getpos=MouseGetPos()
        MouseMove(600, 300, 0)
        MouseClick("Left", 600, 300, 0)
        Sleep($delay)
        MouseMove(200, 250, 0)
        MouseClick("Left", 200, 250, 0)
        $i = $i + 1
    WEnd
    $msgbox=Msgbox(4, "Completed", "Auto-tweeting finished. Return to menu?")
    If $msgbox=6 Then
    ;Startup()
    EndIf
    If $msgbox=7 Then
        Exit
    EndIf
EndFunc


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

So essentially, what I'm asking for is some help/advice/guidance on what I've done wrong, what I could improve and how I could make this script actually work. Comments much appreciated!

[center][u]Scripts:[/u][/center][center]AutoTweet ~ Consequences Game ~ Folder Lock Run+Open[/center]

Link to comment
Share on other sites

More in this direction.

stants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=d:\autoit\koda\forms\autotweeter v1.kxf
$Form1_1 = GUICreate("Form1", 454, 141, 190, 117)
$v1 = GUICtrlCreateLabel("v1", 432, 120, 16, 17)
$text = GUICtrlCreateInput("Enter your text here (140 chars max)", 8, 56, 441, 21)
$ok = GUICtrlCreateButton("Ok", 368, 80, 81, 25, $WS_GROUP)
$times = GUICtrlCreateInput("Number of times to tweet", 8, 80, 169, 21)
$note = GUICtrlCreateLabel("Please note there is a limit to how many times you can tweet in an hour.", 8, 120, 339, 17)
$delay = GUICtrlCreateInput("Delay between tweets (ms)", 184, 80, 177, 21)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Tim again!\My Documents\My Pictures\at.JPG", 8, 8, 209, 41, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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


Func Tweet()
    Sleep(3000)
    For $i = 0 To GUICtrlRead($times)
        Sleep(GUICtrlRead($delay))
        Send(GUICtrlRead($text))
        $getpos = MouseGetPos()
        MouseMove(600, 300, 0)
        MouseClick("Left", 600, 300, 0)
        Sleep(GUICtrlRead($delay))
        MouseMove(200, 250, 0)
        MouseClick("Left", 200, 250, 0)
    Next
    $msgbox = MsgBox(4, "Completed", "Auto-tweeting finished. Press Yes to exit.")
    If $msgbox = 6 Then
        Exit
    EndIf
EndFunc   ;==>Tweet

To obtain values in controls use guictrlread(), the variable assigned to the control contains its ID ($times = ControlID 3), not the value in the control.

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