I've copied the macro to Dragon NaturallySpeaking 10 and find that it doesn't work anymore. The mouse position coordinates are always 0,0 , no matter where the mouse is.
Unfortunately, this macro is way over my head, I don't know how to make it work again. I'd appreciate your help.
Anyway, here's the code:
' Semiautomatically create a mouse position and/or click mouse advanced scripting macro ' tested in Dragon NaturallySpeaking 7.3 pro ' ' Position your mouse pointer, say "mouse position macro" ' Select click and positiong options from the dialog box ' the macro will be coded and ready for naming ' ' '(c)2005 Sean Wenzel All rights reserved. ' http://sean.wenzel.net/voicerecognition/ ' ' This code is released under the following license: ' ' http://www.gnu.org/copyleft/gpl.html '
' the group to create the macro in Const MGROUP = "MyMouse"
' Declare data types and other structures
' ' structure to hold a point ' Public Type POINTAPI x As Long y As Long End Type
' API forward declarations ' get the current cursor position Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
' ' Display a message in the Dragon status bar ' Function DragonMsg(s As String) EngineControl.DragonBar.ShowMessage showmessageNoBeep, s End Function
Sub Main Dim p As POINTAPI Dim macro As String Dim s As String
' get current mouse position GetCursorPos( p )
' create the options dialog Begin Dialog UserDialog 360,273,"Create mouse macro" ' %GRID:10,7,1,1 GroupBox 20,14,320,112,"Position is relative to",.GroupBox1 OptionGroup .Group1 OptionButton 40,35,230,14,"upper-left corner of screen",.opt0 OptionButton 40,56,280,14,"upper-left corner of active window",.opt1 OptionButton 40,77,270,14,"current pointer position",.opt2 OptionButton 40,98,280,14,"upper-left corner of the window interior",.opt5 GroupBox 20,133,190,112,"Click button",.GroupBox2 OptionGroup .Group2 OptionButton 40,154,160,14,"position mouse only ",.optClickNone OptionButton 40,175,150,14,"left click",.optClickLeft OptionButton 40,196,140,14,"right click",.optClickRight OptionButton 40,217,150,14,"middle click",.optClickMiddle GroupBox 220,133,120,63,"Click type",.GroupBox3 OptionGroup .Group3 OptionButton 230,154,90,14,"Single",.optClickSingle OptionButton 230,175,90,14,"Double",.optClickDouble OKButton 230,203,90,21 CancelButton 230,231,90,21 Text 20,252,110,14,"Coordinates are: ",.Text1 Text 140,252,90,14,Str(p.x)+", "+Str(p.y),.lblCoord End Dialog Dim dlg As UserDialog
dlg.Group1 = 0 dlg.Group2 = 0 dlg.Group3 = 0
If Dialog(dlg) = -1 Then
DragonMsg "Creating mouse macro... Position is: " + Str(p.x) + ", " + Str(p.y)
' build the advanced scripting macro macro = "SetMousePosition "
' position relative to... s = "0" Select Case dlg.Group1 Case 0 s = "0" Case 1 s = "1" Case 2 s = "2" Case 3 s = "5" End Select
DragonMsg "Provide a name and description for your macro."
Else DragonMsg "Mouse position macro creation cancelled" End If End Sub
EDIT: Attachment added (BK)
DNS 10 German & French ProDual Boot Windows XP Pro SP3 Ger & Vista Ultimate SP2 Eng. Fujitsu-Siemens S7110 notebook, Intel Core2 T2300, 2x 1.66 GHz, 4 GB RAM, L2 2MB; Mic: Sennheiser CC 550.
Group : Top-tier Member
Active : 09/08/2010 @ 05:44 PM
Posts : 881
Use the following macro, this macro will additionally fill in the add commands box for you. Just call the command something like "add mouse position command" and it will automatically create a mouse position and click command for the current application whatever position the mouse is in. Alternatively just import the XML file below and it will add a global command called "add mouse position command" for you.
' Please note there is no error handling and you may have to adjust the wait times ' at the end of the script when using SendKeys command Option Explicit Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Type POINTAPI x As Long y As Long End Type ' declare Win32 API functions Declare Function GetCursorPos Lib "user32" _ Alias "GetCursorPos" (lpPoint As POINTAPI) As Long Declare Function GetWindowRect Lib "user32" _ Alias "GetWindowRect" (ByVal hwnd As Long, _ lpRect As RECT) As Long Declare Function GetForegroundWindow& Lib "user32" () Function GetWinCurPos(hwnd As Long) As POINTAPI Dim pt As POINTAPI Dim wRect As RECT Dim result As POINTAPI Dim EngineControl As DgnEngineControl GetCursorPos pt GetWindowRect hwnd, wRect result.x = pt.x - wRect.Left result.y = pt.y - wRect.Top GetWinCurPos = result End Function Sub Main Dim hwnd As Long Dim result As POINTAPI Dim clip As String hwnd = GetForegroundWindow result = GetWinCurPos(hwnd) clip = "SetMousePosition 1," & result.x & _ "," & result.y ' you may have to adjust the wait times below EngineControl.DlgShow(dgndlgNewCommandWizard, 0, , 0) Wait 0.4 SendKeys"%y" Wait 0.2 SendKeys"{Down 3}{Tab 2}" Wait 0.2 SendKeys clip Wait 0.1 SendKeys"~Wait 0.2~ButtonClick 1, 1" Wait 0.1 SendKeys"%a" Wait 0.1 SendKeys"%c" End Sub
Group : Top-tier Member
Active : 05/16/2010 @ 04:50 PM
Posts : 172
Lindsay,
Thanks, but I already have a command like that (from you, I think ).
I'm more interested in capturing the mouse position relative to the screen, to the window, current mouse position as shown on the screenshot on Sean Wenzel's website.The screenshot displays a window that appears as soon as the command is given.
I've just written an e-mail to Sean Wenzel concerning an update for the macro. That might be easier. I'll report back.
Boris
DNS 10 German & French ProDual Boot Windows XP Pro SP3 Ger & Vista Ultimate SP2 Eng. Fujitsu-Siemens S7110 notebook, Intel Core2 T2300, 2x 1.66 GHz, 4 GB RAM, L2 2MB; Mic: Sennheiser CC 550.
Group : Top-tier Member
Active : 05/16/2010 @ 04:50 PM
Posts : 172
Sean Wenzel has moved to Apple, so he can't test the macro anymore.
I guess I'll have to improve on my scripting skills (when I find the time...).
Boris
DNS 10 German & French ProDual Boot Windows XP Pro SP3 Ger & Vista Ultimate SP2 Eng. Fujitsu-Siemens S7110 notebook, Intel Core2 T2300, 2x 1.66 GHz, 4 GB RAM, L2 2MB; Mic: Sennheiser CC 550.
Group : Top-tier Member
Active : 09/08/2010 @ 05:44 PM
Posts : 881
Boris, the reason the macro doesn't work is simply because of the line:
GetCursorPos( p )
Just change this to
GetCursorPos p
However this macro is flawed because it doesn't give you the proper coordinates if, for example, you choose the option "upper left corner of active window" and the active window isn't positioned in the top left corner of the screen. You need to add some more Windows API functions to do this properly like in the command I gave you above. Anyway here is a working version of SW's script which is much faster as well because Sean is using HeardWord which is a very slow command. I suggest if you use this script that you only use it for screen position commands and not active window mouse position commands. If I had the time I would modify it for you but I don't and anyway you can use the other command I give you for active window mouse position commands. If for any reason the script I have posted below puts the information in the wrong place of the command wizard then adjust the wait time after the DgnEngine line about 12 lines from the bottom of the script (currently set to 0.7). Finally just to clarify you will get Sean's version working if you simply change the line mentioned above but the version of the script below is faster.
' tested in Dragon NaturallySpeaking 10.1 pro ' modified by Lindsay Adam March 2010 ' (however active window mouse position commands only work ' if active window is positioned in top left-hand corner of primary monitor ' , this is error of original script (other active window script available from LA) ' Position your mouse pointer, say "mouse position macro" ' Select click and positiong options from the dialog box ' the macro will be coded and ready for naming ' ' '(c)2005 Sean Wenzel All rights reserved. ' <http://sean.wenzel.net/voicerecognition/> <http://sean.wenzel.net/voicerecognition/> ' ' This code is released under the following license: ' ' <http://www.gnu.org/copyleft/gpl.html> <http://www.gnu.org/copyleft/gpl.html> '
' the group to create the macro in Const MGROUP = "MyMouse" ' Declare data types and other structures ' ' structure to hold a point ' Public Type POINTAPI x As Long y As Long End Type Dim xcoord As String ' API forward declarations ' get the current cursor position Declare Function GetCursorPos Lib "user32" _ Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
'Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long ' ' Display a message in the Dragon status bar ' Function DragonMsg(s As String) EngineControl.DragonBar.ShowMessage showmessageNoBeep, s End Function Sub Main Dim p As POINTAPI Dim macro As String Dim s As String ' get current mouse position GetCursorPos p ' create the options dialog Begin Dialog UserDialog 360,273,"Create mouse macro" ' %GRID:10,7,1,1 GroupBox 20,14,320,112,"Position is relative to",.GroupBox1 OptionGroup .Group1 OptionButton 40,35,230,14,"upper-left corner of screen",.opt0 OptionButton 40,56,280,14,"upper-left corner of active window",.opt1 OptionButton 40,77,270,14,"current pointer position",.opt2 OptionButton 40,98,280,14,"upper-left corner of the window interior",.opt5 GroupBox 20,133,190,112,"Click button",.GroupBox2 OptionGroup .Group2 OptionButton 40,154,160,14,"position mouse only ",.optClickNone OptionButton 40,175,150,14,"left click",.optClickLeft OptionButton 40,196,140,14,"right click",.optClickRight OptionButton 40,217,150,14,"middle click",.optClickMiddle GroupBox 220,133,120,63,"Click type",.GroupBox3 OptionGroup .Group3 OptionButton 230,154,90,14,"Single",.optClickSingle OptionButton 230,175,90,14,"Double",.optClickDouble OKButton 230,203,90,21 CancelButton 230,231,90,21 Text 20,252,110,14,"Coordinates are: ",.Text1 Text 140,252,90,14,Str(p.x)+","+Str(p.y),.lblCoord End Dialog Dim dlg As UserDialog dlg.Group1 = 0 dlg.Group2 = 0 dlg.Group3 = 0 If Dialog(dlg) = -1 Then DragonMsg "Creating mouse macro... Position is: " + Str(p.x) + ", " + Str(p.y) ' build the advanced scripting macro macro = "SetMousePosition " ' position relative to... s = "0" Select Case dlg.Group1 Case 0 s = "0" Case 1 s = "1" Case 2 s = "2" Case 3 s = "5" End Select macro = macro + s + ", " + Str(p.x) + ", " + Str(p.y) ' click? If dlg.Group2 > 0 Then macro = macro + "{Enter}" Select Case dlg.Group2 Case 1 s = "1" Case 2 s = "2" Case 3 s = "4" End Select macro = macro + "ButtonClick " + s If dlg.Group3 = 0 Then macro = macro + ", 1" Else macro = macro + ", 2" End If End If ' display the add new command wizard ' you may have to adjust the wait times below EngineControl.DlgShow(dgndlgNewCommandWizard, 0, , 0) Wait 0.7 SendKeys" %y" Wait 0.2 SendKeys"{Down 3}{Tab 2}" Wait 0.2 SendKeys macro Wait 0.2 SendKeys"%u" Wait 0.2 SendKeys MGROUP Wait 0.2 SendKeys"%c" DragonMsg "Provide a name and description for your macro." Else DragonMsg "Mouse position macro creation cancelled" End If End Sub
Group : Top-tier Member
Active : 05/16/2010 @ 04:50 PM
Posts : 172
Lindsay,
Thank you so much! I really appreciate the time you are taking to help me and others.
And thank you for the alternative to the HeardWord command.
Just out of curiosity: is there any specific reason why you prefer using wait times after SendKeys statements instead of True? I think I've noticed this in some of your other scripts that you posted on this forum.
Regards, Boris
DNS 10 German & French ProDual Boot Windows XP Pro SP3 Ger & Vista Ultimate SP2 Eng. Fujitsu-Siemens S7110 notebook, Intel Core2 T2300, 2x 1.66 GHz, 4 GB RAM, L2 2MB; Mic: Sennheiser CC 550.
Group : Top-tier Member
Active : 09/08/2010 @ 05:44 PM
Posts : 881
Boris
Thank you and you are welcome, you make a fair point about not using True and it probably is a better method, however the reasoning I use Waits is simply out of habit.
Group : Top-tier Member
Active : 09/08/2010 @ 03:17 PM
Posts : 2586
I am not really sure about using Wait times being a bad habit, in general. I could be wrong but I think I have seen some of my more complex scripts, with a lot of switching back and forth between windows being involved, being at risk to falter if just the "True" or "1" argument is used in SendKeys, which is why I prefer playing it safe and add Wait times throughout.
Group : Top-tier Member
Active : 05/16/2010 @ 04:50 PM
Posts : 172
I generally find True statements sufficient for most operations. I do add them, however, in longer and complex scripts. In the example above I do not find them necessary. I'm not criticizing the use of additional Wait times in general, I just question the need in this context. All of my scripts involving the MyCommands Editor do not require Wait times after SendKeys.
DNS 10 German & French ProDual Boot Windows XP Pro SP3 Ger & Vista Ultimate SP2 Eng. Fujitsu-Siemens S7110 notebook, Intel Core2 T2300, 2x 1.66 GHz, 4 GB RAM, L2 2MB; Mic: Sennheiser CC 550.
Group : Moderator
Active : 09/08/2010 @ 07:01 PM
Posts : 5439
Thread has been edited.
Edit Count :
1 times.
Date Last Edited :
03/06/2010
Time Last Edited :
06:05 PM
Boris,
The only time that you need wait states in any form, whether using the "Wait" or "True" as regards SendKeys, is when there is enough of a delay relative to issuing the SendKeys command(s) that they execute before the situation or application to which they are applied hasn't finished displaying. In most cases, "True" compensates for this, which makes it less prone to such.
"At times we shall simply have to admit that, one way or another, what we can neither explain nor understand certainly doesn't cease to exist because we cannot see how it does or why it should." - Dr. Mark Hyman
Group : Top-tier Member
Active : 09/08/2010 @ 05:44 PM
Posts : 881
Boris
generally speaking I find wait times unnecessary as well and likewise I don't particularly like using them. Problem is if I post scripts on the forum as above and I don't include wait times then it stops the scripts working on quite a few less powerful PCs so my philosophy is always to play safe with wait times.