I want to select words or lines by mouse in a Google Doc, and by script, get these selected words or lines.
Example:
var doc = DocumentApp.getActiveDocument();
var docText = doc.editAsText();
var text = docText.getSelection();
I tried, but I didn't find any methods for selection access like in VBA.
If you want to retrieve text you've highlighted, could try...
Derived from Jonathan's I/O example. However, note that working with cursor position and selections is not yet available as of this writing.
UPDATE: Cursor selection is available now, see docs.
To add to Bryan's answer I wrote this to convert the individual characters to return an array of words or phrases that have been highlighted.
The ability to work with cursor position and selected text was added yesterday, addressing Issue 2865: Get current user location & state information in Document. See the blog post as well.
It turns out that there are some tricks to working with selections. I've tried to show them here - please add comments if you find any others, I'll gladly update.
You are close. I think you want the findText() method.
I'm not familiar with VBA, but this will work to select text in a doc.