0

I wonder whether it is possible to get the cursor context in Dragon NaturallySpeaking's advanced scripting.

By cursor context, I mean the surrounding characters. For example, I sometimes want to condition some steps of a voice command on whether the character preceding the cursor is a space.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

1 Answers1

2

Best I could come up with is my CheckNewPara function shown here: http://knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=2739&discTab=true&messid=11427&parentid=11409&FTVAR_FORUMVIEWTMP=Single

Function CheckNewPara()
    Clipboard$()
    SendKeys "+{Left}^c", True  '  copy previous character
    Select Case Clipboard$()
            Case ""  '  if the prior character is nothing
                    CheckNewPara = ""  '  add no space
            Case Chr(13)&Chr(10), Chr(9), ")"  '  if the prior character is a Lf-CR, tab or )
                    SendKeys "{Right}", True
                    CheckNewPara = ""  '  add no space
            Case "."  '  if the prior character is a period
                    SendKeys "{Right}", True
                    Clipboard$()  '  check for No.
                    SendKeys "+{Left 3}^c", True  '  copy prior three characters
                    SendKeys "{Right}", True
                            If Clipboard$() = "No." Then
                                    CheckNewPara = " "  '  add one space after No.
                            Else
                                    CheckNewPara = "  "  '  add two spaces after period
                            End If
            Case "?", "!"
                    SendKeys "{Right}", True
                    CheckNewPara = "  "  '  add two spaces after other ends of sentence
            Case Else
                    SendKeys "{Right}", True
                    CheckNewPara = " "  '  add one space in the usual case
    End Select
    Clipboard$()
End Function

You should look at the complete topic at http://knowbrainer.com/forums/forum/messageview.cfm?FTVAR_FORUMVIEWTMP=Linear&catid=4&threadid=2739&discTab=true to get all the context, but the code in the post I pointed to should get you started.

My newest version of the function actually calls an AutoHotKey script which looks at both the prior three characters (or as many as there are, if there are any) and the next two characters (or how ever many there are, if there are any) and returns either a space, two spaces, or nothing depending on the context. The context could be a terminal punctuation (requiring two spaces) or a pound/hash # symbol or close paren bracket or brace ) ] } all requiring no spaces, or else by default one space. I also have it so I can call it before and/or after typing in the results of a Dragon command.

HTH, YMMV,

PGilm
  • 2,262
  • 1
  • 14
  • 26