Jump to content
Sign in to follow this  
danibar

access to marked text

Recommended Posts

danibar

hi all,

I want to put inside a variable the text I'm currently marking.

theoreticaly it should be possible by stimulatin CTRL+C, but I want to know if there is any other way.

Thanks,

Daniel

Share this post


Link to post
Share on other sites
Skruge

Welcome to the forums.

It all depends on the application and the control you're dealing with. (Some apps resist automation)

If it's an Edit box, you can get the selection range with _GUICtrlEdit_GetSel and then pull the text out with StringMid & _GUICtrlEdit_GetText.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites
danibar

Thanks!

Im quite new to AutoIt. Can you explain me how to do what you meant?

For exapmle, how can I copy a that is selected in notpad?

Thanks,

Daniel

Share this post


Link to post
Share on other sites
Skruge

Thanks!

Im quite new to AutoIt. Can you explain me how to do what you meant?

For exapmle, how can I copy a that is selected in notpad?

Thanks,

Daniel

#include <GUIEdit.au3>
Global $hEdit, $aPos, $sText

$hEdit = ControlGetHandle("[CLASS:Notepad]", "", "Edit1")
If $hEdit Then
    $aPos = _GUICtrlEdit_GetSel($hEdit)
    If IsArray($aPos) Then
        $sText = StringMid(_GUICtrlEdit_GetText($hEdit), $aPos[0] + 1, $aPos[1] - $aPos[0])
        ClipPut($sText)
        MsgBox(0, "Text copied to clipboard", $sText)
    Else
        MsgBox(0, "Error", "Error reading selection")
    EndIf
Else
    MsgBox(0, "Error", "Couldn't find Notepad's control")
EndIf

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites
danibar

Very nice! thank you.

Is there any way to copy the marked text without considering the window the text was written in?

I want to be able to do some actions on a marked text, where ever the user choose to write it. sort of like babylon....

possible?

Thanks again,

Daniel

Share this post


Link to post
Share on other sites
Malkey

Very nice! thank you.

Is there any way to copy the marked text without considering the window the text was written in?

I want to be able to do some actions on a marked text, where ever the user choose to write it. sort of like babylon....

possible?

Thanks again,

Daniel

This may help.

Highlight some text, then press Ctrl + c.

;
Global $sCopied

HotKeySet("^c", "CopyHighLited"); Ctrl + c To get highlighted text
HotKeySet("{ESC}", "Terminate") ; Esc to exit

While 1
    Sleep(10)
WEnd

Func CopyHighLited()
    ControlSend("", "", "", "^c")
    $sCopied = ClipGet()
    MsgBox(4096, "", $sCopied)
EndFunc   ;==>CopyHighLited

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
;

Share this post


Link to post
Share on other sites
danibar

thank you very much!

I didn't now the control send function...

Thanks

Daniel

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  

×