Jump to content

why wont this button work?


Recommended Posts

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 414, 88, 192, 124)
$TextInput = GUICtrlCreateInput("TextInput", 8, 8, 393, 30)
GUICtrlSetFont($TextInput, 12, 800, 0, "Palatino Linotype")
$Start = GUICtrlCreateButton("Start", 240, 40, 163, 41, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Deley (miniseconds):", 8, 56, 101, 17)
$Delay = GUICtrlCreateInput("Delay", 112, 56, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

Global $Paused

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

Func stop()
    $i = 0
EndFunc   ;==>stop

GUISetState()
$msg = GUIGetMsg()
Select
    case $msg = $Start
        $i = 1
EndSelect
While $i = 0
    Sleep(1000)
WEnd

While $i = 1
    Send($TextInput, 0)
    Sleep($Delay)
WEnd

im sure the solution is simple but i have no idea what it is :S

Edited by joedamoe
Link to comment
Share on other sites

Hi,

1) You are messing around with your while loops.

2) Your Send will send the ControlID of your Inputfield to the active window (see helpfile GUICtrlCreateInput () AND Send ()). Doesn't make sense at all. You might want to send the Data of The Input Field.

Send(GUICtrlRead ($TextInput), 0) -> This will send the data of the input to active window.

3) You might use WinActivate () to activate a specific window before send -> see helpfile for further information.

Heres some code you could go on:

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

Global $Paused, $run = FALSE
HotKeySet("{ESC}", "stop")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 414, 88, 192, 124)
$TextInput = GUICtrlCreateInput("TextInput", 8, 8, 393, 30)
GUICtrlSetFont($TextInput, 12, 800, 0, "Palatino Linotype")
$Start = GUICtrlCreateButton("Start", 240, 40, 163, 41, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Deley (miniseconds):", 8, 56, 101, 17)
$Delay = GUICtrlCreateInput("Delay", 112, 56, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            $run = True
    EndSwitch
    If $run Then
        Send($TextInput, 0); more sense see the remarks above or Melba23's post
        Sleep(GUICtrlRead ($Delay))
    EndIf
WEnd

Func stop()
    $run = False
EndFunc   ;==>stop

;-))

Stefan

@Edit: @Melba23: I missed the GUICtrlRead for $delay. Thanks for further explanation. :mellow:

Edited by 99ojo
Link to comment
Share on other sites

  • Moderators

joedamow,

Welcome to the AutoIt forum. :mellow:

I have played around with your script and it now works as I think you want it (except that I have it writing in the SciTE console rather than Sending to another window):

#include <GUIConstantsEx.au3>

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

Global $Paused = 1

$Form1 = GUICreate("Form1", 414, 88, 192, 124)
$TextInput = GUICtrlCreateInput("TextInput", 8, 8, 393, 30)
GUICtrlSetFont($TextInput, 12, 800, 0, "Palatino Linotype")
$Start = GUICtrlCreateButton("Start", 240, 40, 163, 41)
$Label1 = GUICtrlCreateLabel("Delay (milliseconds):", 8, 56, 101, 17)
$Delay = GUICtrlCreateInput("Delay", 112, 56, 121, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            $Paused = 0
            _Run()
    EndSwitch
WEnd


Func _Stop()
    $Paused = 1
EndFunc   ;==>stop

Func _Run()

    While $Paused = 0
        ConsoleWrite(GUICtrlRead($TextInput) & @CRLF)
        Sleep(Number(GUICtrlRead($Delay)))
    WEnd

EndFunc

The major changes:

1. You need to have a Case for the button in your While...WEnd loop so AutoIt can see when it is actioned.

2. You need some code to run when the button is pressed - here I have used the function _Run.

3. This function runs while $Paused = 0. The HotKey sets $Paused to 1 and so stops the function.

4. You need to use GUICtrlRead to get the contents of the 2 inputs.

5. You had far too many loops!

I hope that is all clear - please ask if not. :(

Given your evident lack of coding experience (not a problem - we all started there :P ) you will find that reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) helps you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :lol:

M23

Edit: Typnig!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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