2

Is there any way to copy the title of the active window to the clipboard in Microsoft Windows in Dragon NaturallySpeaking's advanced scripting?

A workaround I use is to define an AutoHotkey script:

^!l::
WinGetActiveTitle, Title
Clipboard = %Title%
return

and call the keyboard shortcut in the voice command:

enter image description here

but I would prefer not to have to jungle it between AutoHotkey and Dragon NaturallySpeaking. Can it be done in "pure" advanced scripting?

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
  • 1
    The answer is yes (I will post how shortly) but in the meantime, you can use advanced scripting to call up AHK scripts using "ShellExecute" to run an AHK script without having to trigger any hotkey (and you can even pass AHK some command line parameters). Check out http://www.knowbrainer.com/forums/forum/messageview.cfm?catid=25&threadid=22676&discTab=true&messid=130757&parentid=130734&FTVAR_FORUMVIEWTMP=Single (and note, PG LTU is me). – PGilm Jul 21 '16 at 20:53
  • @PGilm Thanks, very good to know! – Franck Dernoncourt Jul 22 '16 at 15:55

1 Answers1

2

Yes, you can copy the title of the active window to the clipboard using Dragon NaturallySpeaking's advanced scripting as follows:

'
'   get window title
'
Sub Main
    Clipboard ( GetWindowTitle )
End Sub
'
'   Use these Windows Functions for Getting an active Window title
'
Declare Function GetForegroundWindow Lib "user32" () As Long
'
Declare Function GetWindowText Lib "user32" _
    Alias "GetWindowTextA" ( ByVal hwnd As Long , _
        ByVal lpString As String , ByVal cch As Long ) As Long
'
'   GetWindowTitle
'   (Gets an active Window title)
'
Function GetWindowTitle() As String
    Dim x As Integer
    Dim TitleText As String * 300
    Dim hw As Long
    hw = GetForegroundWindow()
    x = GetWindowText ( hw , TitleText , Len ( TitleText ) )
    GetWindowTitle = Trim ( Left ( TitleText , x ) )
End Function
'

Now, I keep all the functions in a global '#Uses file (with other declarations, functions and global constants, etc.), so I just need the Main Sub part, but you can put all of the referenced functions and declarations in the one script where you need it, too.

Hth

PGilm
  • 2,262
  • 1
  • 14
  • 26