Sign in to follow this  
Followers 0
Nick Duffill

Accessing selected text in the active window

15 posts in this topic

I want to access the selected text in the currently active window.

$var = ControlCommand(WinGetTitle(""), "", ControlGetFocus(WinGetTitle("")), "GetSelected", "")oÝ÷ Û
+Çâçè­Ê'¶º%²ØZµªÞyØ­rí®lnëbíz¹Þ´LiÞ­ú+{¦¦W¨­æv·¬±¶«Æ§yØ­rí®Sån z+lzWâ²z-jëh×6send("^c", 0)
$var = ClipGet()

works pretty much everywhere, except that it overwrites the Clipboard, which is not so user-friendly.

Is there a third way, or is there a way to save and restore any type of Clipboard contents? As far as I know, ClipGet() and ClipPut() will only save and restore plain text.

Best regards

Nick

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

...but in Internet Explorer, for example, only the address bar is an edit control. The Web page itself is not...

See _IEAction in the help file - specifically, the "selectall" and "copy" parms Edited by herewasplato

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

Share this post


Link to post
Share on other sites

See _IEAction in the help file - specifically, the "selectall" and "copy" parms

Thanks, but this still consumes the Clipboard. I guess there is no way to avoid this.

Regards

Nick

Share this post


Link to post
Share on other sites

Thanks, but this still consumes the Clipboard. I guess there is no way to avoid this.

Regards

Nick

Are you just trying to get the source or something specific?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Are you just trying to get the source or something specific?

What I want to do is use a hotkey to capture the selected text in whatever program is activated at the time. Ideally I would like to avoid using the clipboard to do this, as it would overwrite anything that the user thought they had placed there. So I'm looking for either a way to save and restore the clipboard (allowing send(^c) to be used), or a different way to access whatever is highlighted in the active window, which could be any program.

Thanks for your help

Nick

Share this post


Link to post
Share on other sites

And this doesn't work?

Global $sOldClip, $sNewClip
HotKeySet('{PRINTSCREEN}', '_COPY')
HotKeySet('{ESC}', '_EXITNOW')
While 1
    Sleep(1000000)
WEnd

Func _COPY()
    $sOldClip = ClipGet()
    ControlSend(WinGetHandle(''), '', '', '^c')
    $sNewClip = ClipGet()
    ;Now replace clipboard
    ClipPut($sOldClip)
    MsgBox(64, 'Info', 'Old Clip Stuff:' & @CRLF & $sOldClip & @CRLF & 'New Clip Stuff:' & @CRLF & $sNewClip)
EndFunc

Func _EXITNOW()
    Exit
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

It works with text, not images :whistle:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

It works with text, not images :P

Well ClipPut() won't work with pics :whistle:

I made a work around for this once before I thought.... Maybe it was just to detect if it was a pic... can't remember.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Well can't say :P I've got the same problem :D And I haven't figured a way around :whistle:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Well can't say :P I've got the same problem :D And I haven't figured a way around :whistle:

The only thing I can think of at the moment (Not delving into the memory locations and personally not knowing how to store the information), is if it's a picture, you can return before doing the copy procedure and not do anything.
Global $sOldClip, $sNewClip
HotKeySet('{PRINTSCREEN}', '_COPY')
HotKeySet('{ESC}', '_EXITNOW')
While 1
    Sleep(1000000)
WEnd

Func _COPY()
    $sOldClip = _ClipGetEx()
    If @error Then Return SetError(1, 0, 0)
    ControlSend(WinGetHandle(''), '', '', '^c')
    $sNewClip = ClipGet()
    ;Now replace clipboard
    ClipPut($sOldClip)
    MsgBox(64, 'Info', 'Old Clip Stuff:' & @CRLF & $sOldClip & @CRLF & 'New Clip Stuff:' & @CRLF & $sNewClip)
EndFunc

Func _EXITNOW()
    Exit
EndFunc

Func _ClipGetEx()
    Local $vGetClip = ClipGet()
    If Not @error Then Return $vGetClip
    Local $aClipGetEx = DllCall('user32.dll', 'int', 'CountClipboardFormats')
    If @error = 0 And $aClipGetEx[0] > 4 Then Return SetError(1, 0, 0)
    Return SetError(2, 0, 0)
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks, but this still consumes the Clipboard. I guess there is no way to avoid this.

Regards

Nick

Sorry, I don't know how I missed that part of your request.

SmOke_N's code should work for you...


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

Share this post


Link to post
Share on other sites

Not with images and files :whistle:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Not with images and files :whistle:

Well, the cold hard facts... is that's never been an option. But if you run my last example, you'll see that it won't do anything if it's anything other than text.

Edit:

Might see what you can come up with here: http://msdn2.microsoft.com/en-us/library/ms649051.aspx

Edit2:

_ClipPutFile() is an option for the file issue.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks everyone for all your help and suggestions. For the time being I will position the use of the Clipboard as a feature of the text-grabbing utility instead of a slight complication :whistle:

Best regards

Nick

Share this post


Link to post
Share on other sites

It works with text, not images :whistle:

But the OP and topic title is for text, but I understand...

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

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