enaiman Posted June 1, 2007 Share Posted June 1, 2007 (edited) 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 June 1, 2007 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 More sharing options...
herewasplato Posted June 1, 2007 Share Posted June 1, 2007 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 ;==>_terminateYep - 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 More sharing options...
Gif Posted June 1, 2007 Share Posted June 1, 2007 (edited) Try this one: expandcollapse popup#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 June 1, 2007 by c4nm7 Link to comment Share on other sites More sharing options...
herewasplato Posted June 1, 2007 Share Posted June 1, 2007 (edited) 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 June 1, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Gif Posted June 1, 2007 Share Posted June 1, 2007 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 More sharing options...
enaiman Posted June 1, 2007 Author Share Posted June 1, 2007 (edited) 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 June 1, 2007 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 More sharing options...
Gif Posted June 1, 2007 Share Posted June 1, 2007 (edited) 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 June 1, 2007 by c4nm7 Link to comment Share on other sites More sharing options...
herewasplato Posted June 1, 2007 Share Posted June 1, 2007 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 More sharing options...
Gif Posted June 1, 2007 Share Posted June 1, 2007 (edited) 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 June 1, 2007 by c4nm7 Link to comment Share on other sites More sharing options...
enaiman Posted June 1, 2007 Author Share Posted June 1, 2007 (edited) @herewasplatoBTW, 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.@c4nm7You can identify it using Autoit Info feature , i thinkI can't - believe me ... I've tried Edited June 1, 2007 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 More sharing options...
Gif Posted June 1, 2007 Share Posted June 1, 2007 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 More sharing options...
enaiman Posted June 1, 2007 Author Share Posted June 1, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now