Sign in to follow this  
Followers 0
bigred

Text with "Edit" and "Static" classes.

14 posts in this topic

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?

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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" )


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

..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") ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (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. :ph34r:

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 by bigred

Share this post


Link to post
Share on other sites

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.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (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. :ph34r:

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 by bigred

Share this post


Link to post
Share on other sites

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 :ph34r:

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by bigred

Share this post


Link to post
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
Sign in to follow this  
Followers 0