bigred Posted September 5, 2004 Share Posted September 5, 2004 How can I extract (select and copy) the text from an object on the screen with the class name "Edit" and another named "Static"? The Edit is selectable with my mouse. So far I have used a double mouse click and send keys to copy it to the clipboard, but I don't like this method for obvious reasons. Also what about entering text into a text box with a class of Edit? Link to comment Share on other sites More sharing options...
Developers Jos Posted September 5, 2004 Developers Share Posted September 5, 2004 How can I extract (select and copy) the text from an object on the screen with the class name "Edit" and another named "Static"? The Edit is selectable with my mouse. So far I have used a double mouse click and send keys to copy it to the clipboard, but I don't like this method for obvious reasons. Also what about entering text into a text box with a class of Edit? <{POST_SNAPBACK}>Did you try "Edit1" and "Static1"? Remarks When using a control name in the Control functions, you need to add a number to the end of the name to indicate which control. For example, if there two controls listed called "MDIClient", you would refer to these as "MDIClient1" and "MDIClient2". SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bigred Posted September 5, 2004 Author Share Posted September 5, 2004 Yeah I tried that. I wasn't sure that the Control function could even work with Edit and Static, thats why I was asking. Hmm, let me go over my code again... How would you get the text of a control named Static1 into a variable? Link to comment Share on other sites More sharing options...
Developers Jos Posted September 5, 2004 Developers Share Posted September 5, 2004 How would you get the text of a control named Static1 into a variable? <{POST_SNAPBACK}>Retrieves text from a control. ControlGetText ( "title", "text", "classnameNN" ) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bigred Posted September 5, 2004 Author Share Posted September 5, 2004 ..Thanks I already saw that. That alone won't put the text into a variable. Here is what I have, and it does not work. I was asking for some sample code so that I could compare... Dim $txt WinActivate("App Name", "") $txt = ControlCommand("App Name", "", "Static3", "GetSelected", "") ;Or Static11 MsgBox(4096, "Test Output", "$txt") Link to comment Share on other sites More sharing options...
Developers Jos Posted September 6, 2004 Developers Share Posted September 6, 2004 ..Thanks I already saw that. That alone won't put the text into a variable. Here is what I have, and it does not work. I was asking for some sample code so that I could compare... Dim $txt WinActivate("App Name", "") $txt = ControlCommand("App Name", "", "Static3", "GetSelected", "") ;Or Static11 MsgBox(4096, "Test Output", "$txt") <{POST_SNAPBACK}>This controlCommand gets the selected text from a Edit control. Did you try ControlGetText("App Name", "", "Static3") ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bigred Posted September 6, 2004 Author Share Posted September 6, 2004 Oops that was supposed to be Edit3, not Static3 in my code sample. When I use that code (minus the "" around my $txt var) all that is returned is "1" no matter what the Edit field contains. Link to comment Share on other sites More sharing options...
Developers Jos Posted September 6, 2004 Developers Share Posted September 6, 2004 Oops that was supposed to be Edit3, not Static3 in my code sample. When I use that code (minus the "" around my $txt var) all that is returned is "1" no matter what the Edit field contains. <{POST_SNAPBACK}>Dunno what app you use but here is a working example for Notepad. Start notepad and type a few characters. When no text is entered: ControlCommand ->Fails ControlGetText ->Fails When text is entered but nothing selected : ControlCommand ->Fails ControlGetText ->Returns text When text is entered and selected : ControlCommand ->Returns selected text ControlGetText ->Returns all text Hope this helps.. $txt = ControlCommand("Untitled", "", "Edit1", "GetSelected", "") If @error Then MsgBox(0,"error","Error getting selected text") Else MsgBox(0,"Text",$txt) EndIf $txt = ControlGetText("Untitled", "", "Edit1") If @error Then MsgBox(0,"error","Error getting text") Else MsgBox(0,"Text",$txt) EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bigred Posted September 7, 2004 Author Share Posted September 7, 2004 (edited) Ohhh, that ControlCommand wasn't what I thought it was. So its only good if the user has selected the text. Is there a command for selecting text in an edit?I see how to give it input focus, but no way to select the text without resorting to mouse clicks.Thank you for the explanation!EDIT: Ok I've run into a new problem. I need to send the characters " and ' to an edit. I planned on using either ControlSetText or ControlCommand(EditPaste).I tried using a variable, but thats not compatible with ControlSetText, and since the string I'm trying to send is: text "text" {ENTER} That would require me to use 5 ControlCommand lines. In one string I want to send I will have 20 to 50 variables, so that could start to get out of control. Is there a way to encapsulate a variable in a string? In another Macro language I know they use %variable name% to let you place variables in-line with the string. Or is my only option to use the regular Send command with a variable set to a ASCII value?Only problem there is that I want to use a variable in a ControlSetText string, so I guess I could be out of luck in that case. Edited September 7, 2004 by bigred Link to comment Share on other sites More sharing options...
Developers Jos Posted September 7, 2004 Developers Share Posted September 7, 2004 Not sure if i understand your issue but heres an example that sents variables containing ' and " combined with a string: $test = 'This is a "test" ' $test2 = "This is a 'test2' " ControlSend("Untitled", "", "Edit1", $test & "{ENTER}""extraline""{ENTER}" & $Test2) hope that helps. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bigred Posted September 7, 2004 Author Share Posted September 7, 2004 (edited) Whaat? I would swear that I tried that already... Perhaps the fact that its light outside has something to do with me not getting it to work. How would I get rid of the extra spaces at the end of the variable?Also ControlSend has the same character delay as Send. Will I see reliability problems if I use AutoItSetOption ( "SendKeyDelay", -1 ) and AutoItSetOption ( "SendKeyDownDelay", -1 ) with ControlSend? Because I need the text to send instantly, like with ControlSetText and ControlCommand(EditPaste). Edited September 7, 2004 by bigred Link to comment Share on other sites More sharing options...
Developers Jos Posted September 7, 2004 Developers Share Posted September 7, 2004 Whaat? I would swear that I tried that already... Perhaps the fact that its light outside has something to do with me not getting it to work. How would I get rid of the extra spaces at the end of the variable? <{POST_SNAPBACK}>Just remove it... I put it there for readability SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Administrators Jon Posted September 7, 2004 Administrators Share Posted September 7, 2004 Whaat? I would swear that I tried that already... Perhaps the fact that its light outside has something to do with me not getting it to work. How would I get rid of the extra spaces at the end of the variable? Also ControlSend has the same character delay as Send. Will I see reliability problems if I use AutoItSetOption ( "SendKeyDelay", -1 ) and AutoItSetOption ( "SendKeyDownDelay", -1 ) with ControlSend? Because I need the text to send instantly, like with ControlSetText and ControlCommand(EditPaste). if you need it to work like ControlSetText, why not use ControlSetText. That function is ALWAYS preferable to using Send() unless there is some technical reason why you need to use send()? In order of reliablity I would suggest: 1. ControlSetText 2. ControlSend 3. Send Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
bigred Posted September 7, 2004 Author Share Posted September 7, 2004 (edited) if you need it to work like ControlSetText, why not use ControlSetText. That function is ALWAYS preferable to using Send() unless there is some technical reason why you need to use send()? In order of reliablity I would suggest: 1. ControlSetText 2. ControlSend 3. Send <{POST_SNAPBACK}>Yeah I wanted to use ControlSetText originally but from the help file I didn't think I could encapsulate variables in the string useing text & $var. I think I tried it at one point but I must have made a error. Would ControlCommand(EditPaste) be tied with ControlSetText for stability? Edited September 7, 2004 by bigred 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