Jump to content

Glitch in Send command?


Recommended Posts

Hi,

this is my first post here, so I guess it would be nicer to start with introducing myself. My name is Daniel, live in UK. Discovered AutoIt only a few weeks ago and this is the first programming language for me ever so be gentle please :)

I'm working with a system that is spread out between a Java/XML, '97 MS Access Excel and win file explorer. All under XP.

I've started with a simple script that would fill out a few lines of info. There seems to be a couple of glitches.

a. sometimes one of the full stops doesn't show. It is a minor glitch that I will probably be able to live with

b. the entire list of commands goes into some sort of buffer and gets filled out only after about 20s. This doesn't happen all the time, but will need a workaround if I can't solve it. See my code and links to screenshots below.

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author:      Daniel Tyrkiel

Script Function:
Fill out general order info based on groups of suppliers

#ce ----------------------------------------------------------------------------
; Script Start
WinWaitActive("Order Text to Print on Order.") ;wait for the correct window to pop up
Local $var1 = MsgBox(4, "Which Supplier?", "Is it other than Exp or CZ?") ;primary elimination
Select
Case $var1 = 6
Sleep(200)
Send(".")
Sleep(200)
Send("{DOWN}")
Sleep(200)
Send(".")
Sleep(200)
Send("{DOWN}")
Sleep(200)
Send(".")
Sleep(200)
Send("{DOWN}")
Sleep(200)
Send("Daniel Tyrkiel")
Send("{DOWN}")
Send("01252 89 3363")
Case $var1 = 7
Local $var2 = MsgBox(4, "Which Supplier?", "Is it Express?") ; secondary elimination
Select
Case $var2 = 6 ; if it is express fabrications, then fill the window with info below
WinActivate("Order Text to Print on Order.")
WinWaitActive("Order Text to Print on Order.")
Sleep(200)
Send(".")
Send("{DOWN}")
$var3 = InputBox("Input Works Order Number", "Input works order and customer") ; prompt for bespoke info
WinActivate("Order Text to Print on Order.")
WinWaitActive("Order Text to Print on Order.")
Sleep(1000)
Send($var3)
Send("{DOWN}")
Sleep(200)
Send(".")
Send("{DOWN}")
Send("Daniel Tyrkiel")
Send("{DOWN}")
Send("01252 89 3363")
Case $var2 = 7 ;info to fill if the order is going to CZ
WinActivate("Order Text to Print on Order.")
WinWaitActive("Order Text to Print on Order.")
Sleep(200)
Send(".")
Send("{DOWN}")
$var3 = InputBox("Input Works Order Number", "Input works order and week of completion") ; prompt for bespoke info
WinActivate("Order Text to Print on Order.")
WinWaitActive("Order Text to Print on Order.")
Sleep(1000)
Send($var3)
Send("{DOWN}")
Send(".")
Send("{DOWN}")
Send("Daniel Tyrkiel")
Send("{DOWN}")
Send("01252 89 3363")
EndSelect
EndSelect

https://docs.google.com/file/d/0ByUpE9M4BFXISUc5S1NFT3Z6TTQ/edit

https://docs.google.com/file/d/0ByUpE9M4BFXITkJzRzVrSnNpaDA/edit

Link to comment
Share on other sites

hi Daniel - welcome to the forums!

i changed the window to Notepad for testing. also, you can "Send("{ENTER}")" instead of "{DOWN}" if you need to - i don't know what program you're working with

; we'll idle around untul our window is active
While 1

    Sleep(100)

    If WinActive("[CLASS:Notepad]") Then
        _StringSend()

        ; if we want to keep the script running, we'll idle around until window is not active
        While WinActive("[CLASS:Notepad]")
            Sleep(100)
        WEnd
    EndIf

WEnd

Func _StringSend()

    Local $hWnd, $msg, $input

    ; get window handle for later use
    $hWnd = WinWaitActive("[CLASS:Notepad]") ;wait for the correct window to pop up

    $msg = MsgBox(4, "Which Supplier?", "Is it other than Exp or CZ?")

    ; window already active, so no need to WinActivate()
    If $msg = 6 Then ; yes was selected
        ; we'll send to the Edit class, which is the edit control of the window
        ControlSend($hWnd, "", "[CLASS:Edit]", ". {DOWN} . {DOWN} . {DOWN} Daniel Tyrkiel {DOWN} 01252 89 3363")
    ElseIf $msg = 7 Then ; no was selected
        $msg = MsgBox(4, "Which Supplier?", "Is it Express?") ; secondary elimination
        If $msg = 6 Then ; yes was selected
            ControlSend($hWnd, "", "[CLASS:Edit]", ". {DOWN}")
            $input = InputBox("Input Works Order Number", "Input works order and customer") ; prompt for bespoke info
            WinWaitActive("[CLASS:Notepad]")
            WinWaitActive("[CLASS:Notepad]")
            ControlSend($hWnd, "", "[CLASS:Edit]", $input & "{DOWN} . {DOWN} Daniel Tyrkiel {DOWN} 01252 89 3363")
        ElseIf $msg = 7 Then ; no was selected
            ControlSend($hWnd, "", "[CLASS:Edit]", ". {DOWN}")
            $input = InputBox("Input Works Order Number", "Input works order and week of completion") ; prompt for bespoke info
            WinWaitActive("[CLASS:Notepad]")
            WinWaitActive("[CLASS:Notepad]")
            ControlSend($hWnd, "", "[CLASS:Edit]", $input & "{DOWN} . {DOWN} Daniel Tyrkiel {DOWN} 01252 89 3363")
        EndIf
    EndIf

    ; if we're not going to keep the script running...
    ;Exit

EndFunc

little tip: when you paste AutoIt code, use the AutoIt button - the one to the right of the Code button :)

Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

$handle = WinWaitActive("Order Text to Print on Order.", "",10) ;wait 10 seconds for the correct window to pop up
; $handle = WinGetHandle("[active]") ;for testing only
If @error Then Exit MsgBox(262144, " Input Works Order Number", "Input window not found", 0)
$outvar = InputBox("Input Works Order Number", @LF & "for CZ enter works order and week of completion" & @LF & @LF & _
"for Exp enter works order and customer" & @LF & @LF & "for any other enter '.'", ".", " M", 400, 200)
If @error Then Exit MsgBox(262144, " Input Works Order Number", "No valid input entered", 0)
Sleep(100)
ControlSend($handle, "", "", ".{ENTER}" & $outvar & "{ENTER}.{ENTER}Daniel Tyrkiel{ENTER}01252 89 3363")

Edit: Added sleep command before controlsend.

Edit2: Added error checking after inputbox.

Edited by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Here is your original code in a more structured way, will help you to learn further of what you already know.

WinWaitActive("Order Text to Print on Order.") ;wait for the correct window to pop up
Switch MsgBox(4, "Which Supplier?", "Is it other than Exp or CZ?") ;primary elimination
    Case 6
        _Do_This_1()
    Case 7
        Switch MsgBox(4, "Which Supplier?", "Is it Express?") ; secondary elimination
            Case 6 ; if it is express fabrications, then fill the window with info below
                _Do_This_2()

            Case 7 ;info to fill if the order is going to CZ
                _Do_This_3()

        EndSwitch
EndSwitch

Func _Do_This_1()
    Sleep(200)
    Send(".")
    Sleep(200)
    Send("{DOWN}")
    Sleep(200)
    Send(".")
    Sleep(200)
    Send("{DOWN}")
    Sleep(200)
    Send(".")
    Sleep(200)
    Send("{DOWN}")
    Sleep(200)
    Send("Daniel Tyrkiel")
    Send("{DOWN}")
    Send("01252 89 3363")
EndFunc   ;==>_Do_This_1

Func _Do_This_2()
    WinActivate("Order Text to Print on Order.")
    WinWaitActive("Order Text to Print on Order.")
    Sleep(200)
    Send(".")
    Send("{DOWN}")
    $var3 = InputBox("Input Works Order Number", "Input works order and customer") ; prompt for bespoke info
    WinActivate("Order Text to Print on Order.")
    WinWaitActive("Order Text to Print on Order.")
    Sleep(1000)
    Send($var3)
    Send("{DOWN}")
    Sleep(200)
    Send(".")
    Send("{DOWN}")
    Send("Daniel Tyrkiel")
    Send("{DOWN}")
    Send("01252 89 3363")
EndFunc   ;==>_Do_This_2

Func _Do_This_3()
    WinActivate("Order Text to Print on Order.")
    WinWaitActive("Order Text to Print on Order.")
    Sleep(200)
    Send(".")
    Send("{DOWN}")
    $var3 = InputBox("Input Works Order Number", "Input works order and week of completion") ; prompt for bespoke info
    WinActivate("Order Text to Print on Order.")
    WinWaitActive("Order Text to Print on Order.")
    Sleep(1000)
    Send($var3)
    Send("{DOWN}")
    Send(".")
    Send("{DOWN}")
    Send("Daniel Tyrkiel")
    Send("{DOWN}")
    Send("01252 89 3363")
EndFunc   ;==>_Do_This_3
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

wow, thank you for your quick response. I've tried the first code, but I'm not sure how I can translate the Notepad example to my application. See the image below of the Window Info Tool. The title works replacing [CLASS:Notepad], but I'm not sure what to use for the control.

https://docs.google.com/file/d/0ByUpE9M4BFXIRXJ1cW1jemZkYUk/edit

regards

Daniel

Link to comment
Share on other sites

Right, I've tried [CLASS:SunAwtCanvas;INSTANCE:4] for the edit class and it worked. I'll let you know if I ever get the error with the keystrokes ending up in a "buffer".

If you don't mind I will post more questions as I go. I'll try to adhere to forum rules. All help is greatly appreciated as I really would love to learn this properly.

Many thanks

Daniel

Link to comment
Share on other sites

The Sleep() function does pause execution of the script from which it is called, but any other processes outside of the script (mainly, any other programs that are running..) continue to run, not affected by the Sleep().

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Also I thought I mention that I noticed my own "human" keystrokes geting stuck in the buffer. This makes me think that it isn't an Autoit problem, but rather the software I'm dealing with.

From what I understand, it is only a front to a UNIX based database. So perhaps the software needs to pause for the info to filter through. This is only my guess here as the IT people here haven't got the cource code for the front.

thanks

Daniel

Link to comment
Share on other sites

Because the majority of orders won't be for those two suppliers - CZ or EXP, so the first message box handles 80% of cases.

Hope that clears my muddled logic a bit :)

thanks again

Then you have to press only OK/ENTER for those 80% since this is the default (".")

App: Au3toCmd              UDF: _SingleScript()                             

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