Nice work-arounds for DNS preffered's lack off support for real commands or even text substitutions that send keystrokes. When I was stumped by this issue, I found Natpython & Vocola here:
http://speechwiki.org/NL/HomePage.html. These, respectively, use the NatLink utility of DNS to accept python scripts and convert DNS (v3) scripting language to python.
Keystroke commands are easy to write and they CAN call hotstrings/hotkeys in autohotkey. Vocola also supports variables, captured words and alternatives. Moreover, the DNS script command AppBringUp can pass parameters to autohotkey.
I select tools in a toolbar (which DNS8 does not support) with the following code:
Icon_finder.ahk
Code:
; This script searches the entire screen or a limited area of the screen for an icon in a supported graphic format
; It is designed to be called by another program as required using a command line shell type call
; -- AppBringUp in the Vocola-NatLink implementation of the Naturally Speaking script language
;
; eg. AppBringUp(icon,"AutoHotkey /icon_finder.ahk param1 param2 param3 param4 param5 param6",6,dir) for a full-screen search or
; AppBringUp(icon,"AutoHotkey /icon_finder.ahk param1 param2 param3 param4 param5 param6 param7 param8 param9 param10 param11",6,dir)
; for a limited area search
;
; C: is prefixed to /icon_finder.ahk when this call is made, I don't know which program does it.
; Icon and Param1 are the name of the icon file.
; The quoted part is the command line parameter in AppBringUp (quotes required).
; The next number specifies the state for the window (6 is minimized/inactive).
; Finally, the call has a working directoy parameter, dir. This permits simplification of param1 because A_WorkingDir
; below then contains the path to the icon file (a path passed in param1 throws vocola for a loop).
;
; The the autohotkey script reads the command line parameters param1-param11 as follows:
; In the command line parameter a param2 = "L" means the next four parameters specify the upper left and lower right coordinates
; of the area to be searched as fractions of the full-screen width and height. If L is not set a full-screen search is accomplished
; (fractional coordinates must not be sent either in this case).
; The mouse is offset from the upper left corner of the icon the next two parameters and clicked by following one (0-2 clicks may be
; sent). The remaining parameters get the mouse off the icon (toward the upper left, if negative or lower right if positive), and
; allow for color mismatch in the icon (0-255), respectively.
#NoTrayIcon
LimitArea = %2%
X2 := (A_ScreenWidth)
Y2 := (A_ScreenHeight)
IfNotInString, LimitArea, S
{
WinGetPos, X, Y, Width, Height, A
X2 := width
Y2 := height
}
else
{
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
LimitArea = "L"
}
IfInString, LimitArea, L
{
c1 = %3%
c2 = %4%
c3 = %5%
c4 = %6%
X1 := (X2*c1)
Y1 := (Y2*c2)
X2 := (X2*c3)
Y2 := (Y2*c4)
ShiftX = %7%
ShiftY = %8%
Clicks = %9%
ShiftBack = %10%
MatchColor = %11%
}
else
{ X1 := 0
Y1 := 0
ShiftX = %2%
ShiftY = %3%
Clicks = %4%
ShiftBack = %5%
MatchColor = %6%
}
ImageSearch, FoundX, FoundY, %X1%,%Y1%,%X2%,%Y2%, *%MatchColor% %A_WorkingDir%\%1%
if ErrorLevel = 2
MsgBox Could not conduct the search for %A_WorkingDir%\%1%.
else if ErrorLevel = 1
MsgBox Icon %A_WorkingDir%\%1% could not be found on the screen.
else
{ MouseMove FoundX, FoundY
Click %ShiftX%, %ShiftY%, %Clicks%, relative
If ShiftBack != 0
MouseMove (FoundX+ShiftBack), (FoundY+ShiftBack)
}
return
The vocola code that calls this looks like this:
Code:
# Icon finder calls for icon based clicking
# IconFinder opens the process from DNS as "icon" in a minimized
# window ("6"), passes the ahk commandline ($i), and path to the icon
# ($p). CallLimitedIconFinder assembles the command line
# so that white space doesn't foul the AppBringUp call. The voice
# commands are "your icon" and "another tool" defined
# as bit maps "your_icon" and "another_tool".
IconFinder (i,p) :=
AppBringUp(icon, $i, 6, $p);
CallLimitedIconFinder (icon, flag, yupper, xleft, ylower, xright, xshift, yshift, clicks, offset, match, path) :=
IconFinder("AutoHotKey /icon_finder.ahk "$icon".bmp "$flag" "$yupper" "$xleft" "$ylower" "$xright" "$xshift" "$yshift" "$clicks" "$offset" "$match, $path);
(your icon = your_icon | another tool = another_tool) = CallLimitedIconFinder($1, S, 0.75, 0.75, 1, 1, 5, 5, 0, 0, 50,"C:\My Scripts\icons");
Icon bitmaps can be cut from screens captured using CaptureScreen (Sean's script
http://www.autohotkey.com/forum/topic18146.html using paint. This is automated somewhat with this code in front of the CaptureScreen code:
Code:
;
; Script Function:
; Capture icons for later selection by icon based search
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoTrayIcon
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
; Interface script to permit Dragon Naturally Speaking via NatPython/Vocola to issue a call to CaptureScreen() to capture an icon
; to select with ImageSearch in subsequent calls to the IconFinder script
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
xshift = %1%
yshift = %2%
PosX1 := xpos - xshift/2
PosY1 := ypos - yshift/2
PosX2 := xpos + xshift/2
PosY2 := ypos + yshift/2
C1 = %PosX1%,%PosY1%,%PosX2%,%PosY2%
IconArchive = %A_WorkingDir%\%3%
MouseMove, 0, 0
CaptureScreen(c1, false, IconArchive)
MouseMove xpos, ypos
SplashImage, %IconArchive%, H150 W400,,This is how it looks!
FileSelectFile, SelectedFile, S, temp, Save As, bitmaps (*.bmp)
If SelectedFile =
SplashImage, Off
Else
{
FileCopy, %IconArchive%, %SelectedFile%.bmp, 1
SplashImage, Off
}
Return
; CaptureScreen goes here
Then call from vocola:
Code:
# Capture a bit map around the mouse pointer for use with IconFinder.ahk
<n> := 0..99;# n is a variable values 1-99
capture (a) <n> by <n> icon = AppBringUp(IconCapture, "AutoHotKey /IconCapture.ahk $2 $3 temp.bmp", 6, "C:\My Scripts\icons"); # save temporay n by n bmp in specified path
edit the last icon = AppBringUp(Paint,"\windows\system32\mspaint temp.bmp",1,"C:\My Scripts\icons");# shows the bmp in paint
edit an icon = AppBringUp(Paint,"\windows\system32\mspaint temp.bmp",1,"C:\My Scripts\icons")
SendKeys {alt+f}o;# as above but opens "open" dialog too
The above approach allows me to run software with a very highly graphical interface by voice. A little cross pollination of autohotkey and vocola-natpython seems to help. See what you think.