Jump to content

Endless function


Recommended Posts

I've been testing the ControlSend to an empty control and I wrote a small script to test if ControlSend is working when the window is active/inactive.

here is the script:

#include <GUIConstants.au3>

AutoItSetOption("GUIOnEventMode",1) 
AutoItSetOption("WinTitleMatchMode",2) 
$Form1 = GUICreate("Form1", 248, 240, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$Input1 = GUICtrlCreateInput("Input1", 32, 24, 161, 21)
$MyButton1 = GUICtrlCreateButton("MyButton1", 16, 184, 100, 30)
GUICtrlSetOnEvent($MyButton1, "trtt")
GUISetState(@SW_SHOW)
Run ("notepad")

While 1
    Sleep (200)
WEnd

Func close ()
    Exit
EndFunc

Func trtt ()
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
    ControlSend ("Notepad", "", "","hgdh"&@CR)
    Sleep(2000)
EndFunc

What I've got? the function trtt() is executed over and over - IMHO this function should be executed once and return to the waiting loop.

Am I doing something wrong here?

ControlSend fails to send anything once Notepad window is inactive (once $Form1 is activated)

What is wrong here??

Thanks for any help.

AutoIt version: 3.2.4.9

OS: Win XP Pro SP2 build 2600

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I have no idea why your GUI repeats the function, but you can try this:

AutoItSetOption("WinTitleMatchMode", 2)

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

While True
    If WinExists("Notepad") Then
        ControlSend("Notepad", "", "", "hgdh" & @CR)
        ToolTip("sent")
        Sleep(1000)
        ToolTip("")
        Sleep(1000)
    EndIf
WEnd

Func _terminate()
    Exit
EndFunc   ;==>_terminate
Yep - it does not send to the notepad window unless it is active. Don't know why?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Try this one:

#include <GUIConstants.au3>


Opt("WinTitleMatchMode",2) 
 $Form1 =  GUICreate("Form1",  248,  240,  193,  115)
$Input1 =  GUICtrlCreateInput("Input1",  32,  24,  161,  21)
$MyButton1 =  GUICtrlCreateButton("MyButton1",  16,  184,  100,  30)
GUISetState(@SW_SHOW)

Run ("notepad")

While  1
     $nmsg = GUIGetMsg()
     Select
        Case $nmsg = $GUI_EVENT_CLOSE
            Exit
        Case $nmsg = $MyButton1 
            trtt()
    EndSelect   
WEnd



Func trtt  ()
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
     ControlSend  ("Notepad",  "",  "Edit1","hgdh"&@CR)
     Sleep(2000)
EndFunc
Edited by c4nm7
Link to comment
Share on other sites

c4nm7,

You cheated :-)

You used "Edit1".

The point of the test was to use ControlSend without a Control...

It used to work - or so I'm told.

Edit: BTW, the code in the first post was not endless, but sometimes would repeat - perhaps the ControlSend was pressing the button of the GUI when Notepad was not active.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

c4nm7,

You cheated :-)

You used "Edit1".

The point of the test was to use ControlSend without a Control...

It used to work - or so I'm told.

Edit: BTW, the code in the first post was not endless, but sometimes would repeat - perhaps the ControlSend was pressing the button of the GUI when Notepad was not active.

I cheated? but it works? and that was a test? probably the fault is my bad english...

but it would be

ControlSend("Untitled", "", "Edit1", "This is a line of text in the notepad window")

this in HELP file

Link to comment
Share on other sites

Thanks for help herewasplato and c4nm7

c4nm7 worked perfectly (even ControlSend worked regardless of the state of Notepad window.

What I can see is a simple mode change from OnEventMode to ... how it is called? .. and nothing else changed.

This is really weird ... the OnEventMode seem to be bugged. I don't know why this is happening but I think definitely someone needs to look at (I mean some1 from the development team)

My God - I have a huge script made in OnEventMode and I have to change it ... :)

EDIT:

Arghh ... haven't noticed "Edit1" - the purpose was to send to an empty control ... now I'm really sad because it definitely shows that ControlSend to an empty control doesn't work :)

Notepad here was only to give the people helping me something to test my code - what I'm using is TeraTerm to configure network switches and there, unfortunately, I don't have the luxury of identifying the ControlID.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I cheated? but it works? and that was a test? probably the fault is my bad english...

but it would be

ControlSend("Untitled", "", "Edit1", "This is a line of text in the notepad window")

this in HELP file

hmm this must be what i should have read...

I've been testing the ControlSend to an empty control and I wrote a small script to test if ControlSend is working when the window is active/inactive.

:)  

Thanks for help herewasplato and c4nm7

c4nm7 worked perfectly (even ControlSend worked regardless of the state of Notepad window.

What I can see is a simple mode change from OnEventMode to ... how it is called? .. and nothing else changed.

This is really weird ... the OnEventMode seem to be bugged. I don't know why this is happening but I think definitely someone needs to look at (I mean some1 from the development team)

My God - I have a huge script made in OnEventMode and I have to change it ... :)

I dont think that OnEventMode is bugged cause a lot of people used it , using it and will use it with no problem, i saw many scripts with OnEventMode and no problem occured;;;

I cant understand what the problem excacly was so i tryed the classic method with Select-Endselect

[if there is a bug then you should report it to the Bugs Report Forums] 

Edited by c4nm7
Link to comment
Share on other sites

c4nm7,

Yeah - that is why the smiley face after the "cheated". I was not seriously calling you a cheat - just pointing out that there were two problems mentioned in the oringinal post. I have seen several posts about using ControlSend without a Control. See this for for example:

http://www.autoitscript.com/forum/index.ph...showtopic=45811

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Notepad here was only to give the people helping me something to test my code - what I'm using is TeraTerm to configure network switches and there, unfortunately, I don't have the luxury of identifying the ControlID.

You can identify it using Autoit Info feature , i think ;;;

A moderator would know better

Edited by c4nm7
Link to comment
Share on other sites

@herewasplato

BTW, the code in the first post was not endless, but sometimes would repeat - perhaps the ControlSend was pressing the button of the GUI when Notepad was not active.

Yep - that should be the explanation.

You're definitely right because it stops after a while if $Form1 is not active.

@c4nm7

You can identify it using Autoit Info feature , i think

I can't - believe me ... I've tried

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Using the AutoIt Window Info Tool you can move your mouse around the window you are interested in and you will be given information of the control that is currently under your mouse.

this is what Help file writes, there might not be any way to send to an *unidentified window

*:think that's wrong :)

if that feature worked then you can report it either to Bug Reports or in Feature Requests ;;

Link to comment
Share on other sites

You see ... sometimes you simply can't identify a controlID - it happened to me many times, AutoIt Info tool simply can't identify the controls and it is not its fault ... maybe in the future ... who knows. Until then we need to find workarounds.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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