How to Get Selected Text without Using the Clipboard
I'm trying to get some text that is selected (in, word, on the internet, etc.) WITHOUT using the clipboard.
How do I do this?
Thanks
I have NO idea how to use this...
Feel free to ask if you need further assistance. It does get a bit tricky, with MSDN's lack of documentation for messages.
sumon has an excellent point here. Not only is the clipboard fast, but it works in places where messages don't.For most purposes, why not using the Clipboard? Given that you restore it afterwards, that is. Someone (Learning One?) has a nice Get Selected Text function, GST().
The clipboard can be restored, so I don't see any reason to not use it, only reasons to not use SendMessage.
Is it when we don't see a reason for something that we give up helping finding a solution?
Based on the first post, there was no indication as to why the non-clipboard request.
If someone needs basic help, but does not realize which kind of help he/she needs, it is better to help them in a way that is actually useful than to (sometimes in vain) try to help them in a far too advanced way.
For example, if I saw someone ask "Hey, how can I make a script in C++ that lets me type "I am the king of the world" when I press windows+k?", I would tell them to use Autohotkey for the task instead. If someone on the other hand described a problem where AHK was clearly not the appropiate solution (let's say they were making an application and wanted to implement a specific function that would be easier to implement in AHK, but the program was already in another language...), then I would of course simply not reply.
Answer 'nuff?
Here's an example that gets text from edit controls using ControlGet. It has a clipboard backup for non-edit types:
WinActive("A") ; sets last found window ControlGetFocus, ctrl if (RegExMatch(ctrl, "A)Edit\d+")) ControlGet, text, Selected,, %ctrl% else { clipboardOld := Clipboard Send, ^c if (Clipboard != clipboardOld) { text := Clipboard Clipboard := clipboardOld } } MsgBox % text
@sumon: Agreed. No sense in wasting time As for me making assumptions, I don't mind. I have too much time on my hands, so I don't mind going with my instinct (even if it is a waste) on first post. I'm also bi-polar and will probably go months without helping here. So I do what I can while I can.
Besides, it might be fun to come up with a solution to the requested problem instead of just giving basic advice.
Seems Solar has some nice advice too.
As for a reason not to use the clipboard, I have found a use-case for those who assumed that since they can't think of a use-case, one must not exist:
Suppose you wanted to copy all the lines from a QuickBooks invoice into an Excel spreadsheet (AHK could be a great way to overcome Intuit's vendor lock-in). Using AutoHotKey, you can copy each line into Excel using the Clipboard. There is only one problem: There's no way for AHK to tell when the end of the QuickBooks invoice has been reached.
You could try to stop copying when you've copied a blank line, but QuickBooks puts a stop to this: If you try to copy a blank line, QuickBooks simply ignores the ^C input, so the Clipboard will not become empty. Instead, it'll still have whatever was on the Clipboard before.
If you could look at the active selection without needing to get QuickBooks to copy it to the Clipboard, you could check if that selection was empty or nonexistent, and use that to terminate the loop, but there is absolutely no way to achieve this using just the Clipboard.
So, how do we get the selected text without relying on the Clipboard?