Jump to content

Action Interfer


Line
 Share

Recommended Posts

Hey,

I'm new to AutoIT scripting and I'm trying to create a small auto-action that writes something for me in notepad.

I choose what to write and the delay time.

I looked at a tut on the web on doing it but the problem is that the actions kinda are impossible to stop.

If I press the start button and the words are wrote in notepad,I can't press the "x" button on the bot.

http://puu.sh/6xunS/433f129c4d.jpg <Image

And this is the code:

#include <GUIConstantsEx.au3>

GUICreate("Konrad Story Teller",335,100)

GUICtrlCreateLabel("Word",8,10)
$key1 = GUICtrlCreateInput("",35,8,120)
GUICtrlCreateLabel("Time",8,44)
$time1 = GUICtrlCreateInput("",35,40,120)

$startbutton = GUICtrlCreateButton ("Start",190,8,60)


GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $startbutton
                $send1 = GUICtrlRead($key1)
                $sleep1 = GUICtrlRead($time1)
            While 1
                Send($send1)
                Sleep($sleep1)
            WEnd
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

    EndSelect

WEnd
Link to comment
Share on other sites

It's better to use hotkeys to start/stop so you don't have to switch between windows and have stuff written all over.
I've made it like this : First you save your settings, then you use CTRL+F1 to start sending and CTRL-F2 to stop sending. Also, the time is multiplid by 1000 so it's in seconds, not milliseconds.

#include <GUIConstantsEx.au3>
GUICreate("Konrad Story Teller",335,100)
GUICtrlCreateLabel("Word",8,10)

$key1 = GUICtrlCreateInput("",35,8,120)
GUICtrlCreateLabel("Time",8,44)
$time1 = GUICtrlCreateInput("",35,40,120)
$startbutton = GUICtrlCreateButton ("Save",190,8,60)
GUISetState(@SW_SHOW)

Global $keepSending = False
Global $send1 = ""
Global $sleep1 = 0
HotKeySet("^{F1}","startSending")
HotKeySet("^{F2}","stopSending")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $startbutton
                $send1 = GUICtrlRead($key1)
                $sleep1 = GUICtrlRead($time1)*1000
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
    EndSelect
WEnd

Func startSending()
    $keepSending = True
    While $keepSending
        Send($send1)
        Sleep($sleep1)
    WEnd
EndFunc

Func stopSending()
    $keepSending = False
EndFunc
Edited by Inverted
Link to comment
Share on other sites

Have a look at your while loop.

While 1

Send($send1)

Sleep($sleep1)

WEnd

Here you are not checking anything what happens on your gui. You have te re-add a check for your the exit button like here:

While 1

Send($send1)

Sleep($sleep1)

Local $msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

Exit

;GUIDelete()

;ExitLoop

EndIf

WEnd

(Sorry for the messy code, my editor on the forum is bugged, I can't use BB tags)

Link to comment
Share on other sites

No no Inverted,its awesome,its just that I don't currently want to press keys to activate it.I could have used winwait for my notepad so the text won't be written all over.

Another question for you guys:

If I would delete the label "time" there and  the input from it.And modify a bit the code to make my little program a bot to set any window I want on top,how would I make the WinSetOnTop command read what the user writes?

This is the modified version of the upper script:

#include <GUIConstantsEx.au3>

GUICreate("Konrad's:Always On Top",335,100)

GUICtrlCreateLabel("Window Title:",8,10)
$win = GUICtrlCreateInput("",35,8,120)

$startbutton = GUICtrlCreateButton ("TopIT",190,8,60)


GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $startbutton
                $win1 = GUICtrlRead($win)
            While 1
                WinSetOnTop($win1) ; ??????
            WEnd
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

    EndSelect

WEnd
Link to comment
Share on other sites

Can I use ControlSend with the text got from a input as example?

Piece of code:

$input = GUICtrlCreateInput("",x,y)
$startbt = GUICtrlCreateButton("",x,y,z,w)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $startbt
                $input1 = GUICtrlRead($input)

            While 1
                                 ControlSend($input1,"","Edit","RandomText")
Edited by Line
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...