![]() |
KnowBrainer Speech Recognition | ![]() |
Topic Title: custom command to select current sentence Topic Summary: Created On: 09/17/2021 07:54 PM Status: Post and Reply |
|
![]() |
![]() |
- wristofdoom | - 09/17/2021 07:54 PM |
![]() |
![]() |
- Alan Cantor | - 09/17/2021 08:39 PM |
![]() |
![]() |
- wristofdoom | - 09/17/2021 10:18 PM |
![]() |
![]() |
- Alan Cantor | - 09/18/2021 11:36 PM |
![]() |
![]() |
- Alan Cantor | - 09/19/2021 06:13 PM |
![]() |
|
Does anybody have a custom command for selecting the current sentence that (mostly) works in any application?
I know that such a command will not be perfect, and will not pick up on common sense ideas about what constitutes a sentence.
However, a command that will move the caret left until it hits a "." character, and then move/select to the right until it hits another "." character seems achievable, albeit clunky.
My pseudocode would look something like this:
sendkeys "^{left}" // move one word to the left SendKeys "+{left}" // select one character to the left SendKeys "^v" // get the selected character into the clipboard //do some fancy logic I don't know how to do, to test if the selected character is a "period" or not. If no, then repeat the above. If yes, then start doing a new loop: SendKeys "{right}" // deselect the character SendKeys "^{right}" // move one word to the right SendKeys "+{right}" // select one character to the right //do some logic to test to see if the character is a ".". // If not, then increment a counter by 1, because we need to know how many words apart the two periods are from each other // Continue to loop the ^{right} command, and test each character to the right after each jump to see if the character is a period, and increment the counter by 1 every time it is NOT a period // when you finally reached a period, then select back X amount of words, using SendKeys "+^{left}" were X = value of the counter
This is how I would do it as a human using the keyboard, but sounds very slow and buggy.
Anybody have a better way?
------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
|
![]() |
|
In Word and Outlook messages, pressing F8 three times selects the sentence. It doesn't matter where the cursor is in the sentence. The command automatically finds the start and end of the sentence: |
|
|
|
![]() |
|
Yeah I know that some apps have it. Writemonkey has it too.
What I am trying to achieve is an app-neutral way to get the sentence on the basis of delimiters. ------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
|
![]() |
|
This AutoHotkeyScript, triggered by pressing Alt + 1, probes left, character by character, to identify the start of a sentence. And then it probes right to find the end of the sentence. And then it selects the sentence.
The script will fail at times. For example, it goes into an infinite loop when the sentence is the first in a field or a document. The script only recognizes the period/full stop as a sentence delimiter. For the last sentence in a field or document, an extra character might be selected. The script also runs rather slowly. Despite the limitations of the script, hopefully it's a step in the right direction. Feel free to use and modify it. It can be improved. !1:: CountLeft = 0 CountRight = 0 ; Probe left to end of previous sentence Loop { Clipboard := "" SendInput +{Left}^c ClipWait 0.1 SendInput {Left} ++CountLeft If (Clipboard = .) { Break } } SendInput {Right %CountLeft%} ; Probe right to end of current sentence Loop { Clipboard := "" SendInput +{Right}^c ClipWait 0.1 SendInput {Right} ++CountRight If (Clipboard = .) { Break } } ; Select the sentence Send +{Left %CountRight%} CountLeft := CountLeft - 2 Send +{Left %CountLeft%} |
|
|
|
![]() |
|
Here is a slightly more robust version. The script now treats periods, question marks, and exclamation marks as sentence delimiters. It watches for the start of a document or field; the script doesn't loop forever for the first sentence. The selection is more accurate when there is more than one space between sentences.
The script doesn't deal with multiple delimiters in a row!! Like this??? Yes...
The script still might fail or be inaccurate under certain conditions, but so far, it seems to work well, albeit slowly. There is still room for improvement. Hopefully someone who knows AutoHotkey better than I do will take that on.
This is an AutoHotkey script triggered by Alt + 2. Not sure the code can be "translated" into Advanced Scripting or DVC... that's not a project I can take on!
!2:: Offset = 0
; Probe LEFT by character to the previous sentence delimiter. Also check for start of field/document Loop { Clipboard := "" SendInput +{Left}^c ClipWait 0.1 SendInput {Left}
If (Clipboard = .) or (Clipboard = "!") or (Clipboard = "?") { SendInput {Right} Break }
If (Clipboard = "") ; Insertion point is at the start of field or document { Break } }
; Probe RIGHT by character until a non-space is reached Loop { Clipboard := "" SendInput +{Right}^c ClipWait 0.1 SendInput {Right}
If (Clipboard != " ") ; Assume there are spaces between sentences, not tabs or anything else. { SendInput {Left} Break } }
; Probe RIGHT by character until a sentence delimiter is reached Loop { Clipboard := "" SendInput +{Right}^c ClipWait 0.1 SendInput {Right} ++Offset
If (Clipboard = .) or (Clipboard = "!") or (Clipboard = "?") { Break } }
SendInput +{Left %Offset%}
Return |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.