KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: How to remember mouse position and return to it?
Topic Summary:
Created On: 01/05/2018 06:04 PM
Status: Post and Reply
Linear : Threading : Single : Branch
Keyword
 01/05/2018 06:04 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 12
Joined: 01/05/2018

I have a very basic question that I can't find the answer to on the forum that I can't find the answer to on the forum.  Namely, what is the command to return the mouse to the position I saved with RememberPoint?  I know about DragToPoint, but I don't want to drag anything, I just want to move the mouse back to where it was.  What am I missing?



-------------------------

Avery 

 01/05/2018 06:34 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 40717
Joined: 10/01/2006

                    Welcome to the World's Most Popular Speech Recognition Forum


Unfortunately, we can't remember if Dragon can temporarily remember a Mouse Position (by recording the coordinates to the clipboard) but your KnowBrainer 2017 command utility includes 3 commands that can record the current Mouse Position if that helps.


1.  Mouse Location records the current X and Y mouse coordinates to the clipboard to be used in building mouse commands in professional versions of Dragon or KnowBrainer.


2.  Find Mouse Position is a variation on the previous command.


3.  New Mouse Command <dictation> records the current X and Y mouse coordinates, creates a new application-specific command, names the command, pastes the X and Y coordinates into the script, adds a mouse Left Click and saves the command in about 2 seconds. For example, if we wanted to create a KnowBrainer application specific Mouse Position command to Left Click on the Crop symbol in Photoshop, we can position our mouse over the crop symbol and say New Mouse Command <crop> which will create a Photoshop application-specific mouse command called “Crop”.



-------------------------

Change "No" to "Know" w/KnowBrainer 2022
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ex 1

 01/05/2018 06:53 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 12
Joined: 01/05/2018

Thanks for the quick response, and this is a very helpful command to use. But I was asking something different. I am trying to write a command in which I [1] save the current mouse position, [2] go and do something else on a different part of the screen, and then [3] reposition the mouse to where it originally was. It's step [3] that I'm having trouble with.

-------------------------

Avery 

 01/05/2018 06:57 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 12
Joined: 01/05/2018

And just to clarify - I want to be able to do this for any original mouse position - not for a fixed location on the screen such as a particular icon.

-------------------------

Avery 

 01/05/2018 10:26 PM
User is offline View Users Profile Print this message

Author Icon
Grindcore
Power Member

Posts: 73
Joined: 07/17/2015

You can store your mouse position in a variable by putting this code at the start of your script (before Sub Main):

 

Type POINTAPI

xx As Long

yy As Long

End Type


Declare Function GetCursorPos Lib "user32" _

  Alias "GetCursorPos" (lpPoint As POINTAPI) As Long


Private Mpos As POINTAPI


Sub Main

Now here goes your script as usual, but to store the mouse position, you can now use this use this:

 

GetCursorPos Mpos

 

This will store your cursor's location X and Y coordinates in the variables Mpos.xx and Mpos.yy

And to put your cursor at the stored coordinates you can use this:

 

SetMousePosition 0,Mpos.xx,Mpos.yy

 



 01/06/2018 10:02 AM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 12
Joined: 01/05/2018

Wow, thanks. I had assumed this could be done with a pre-existing command as opposed to programming, but I will try this. Thanks a lot.

-------------------------

Avery 

 06/01/2018 04:51 PM
User is offline View Users Profile Print this message

Author Icon
Mark Bennett
New Member

Posts: 3
Joined: 05/27/2018

I borrowed some command from this page and other posts on the form. The command I came up with (after very minimal editing) copies the mouse coordinates (based on the screen position, not the window). The next command moves the mouse to the copied coordinates. I needed this to be a 2-command process. The downside is that it uses the clipboard. If someone finds errors in this, please let me know. If someone knows how to duplicate this code without using the clipboard, please let me know also.

1)MOUSE LOCATION COPY COMMAND (based on screen coordinates only)


Type POINTAPI 'Declare types

x As Long
y As Long
End Type

Dim Pre as String
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 'Declare API
Dim z As POINTAPI 'Declare variable

Sub Main

GetCursorPos z 'Get Coordinates
Pre = "The captured screen-relative mouse position was: X = "
X$ = Str$(z.x)
Y$ = Str$(z.y)
Let Sp = " Y = "

Let S = Pre+X$+Sp+Y$
'MsgBox S, 0, "Get Mouse Screen Position"   '  This was in the original code
Let SpC = ","
C$ = X$+SpC+Y$
Clipboard C$ 'this statement compiles but causes a runtime error

End Sub


2)MOUSE 'PASTE' COMMAND

Sub Main
clip = Clipboard
Dim LString As String
Dim LArray() As String

LString = clip
LArray = Split(LString, ", ")
SetMousePosition 0,LArray(0),LArray(1)




End Sub



-------------------------

Mark Bennett, Learning about Computer Disability Accomodations



 06/03/2018 03:46 PM
User is offline View Users Profile Print this message

Author Icon
Mphillipson
Top-Tier Member

Posts: 311
Joined: 09/22/2014

So I guess you need to have a way of storing the mouse coordinates on the fly without resorting to the clipboard, which could potentially get overwritten anyway.

 

What you need is a way to persist the Mouse Coordinates between the two scripts:

 

Save Mouse Position

 

Go to Last Mouse Position

 

I use a database for this purpose:

 

https://www.screencast.com/t/55fbxYZNmy65

 

If that's a little over your head you can alternatively use a text file to temporarily store the value in the first script.  And then use code to open the text file and read its contents in the second script.

 

Here's an example function to load the text:

 

Function FileText (filename$) As String

    Dim handle As Integer

    handle = FreeFile

    Open filename$ For Input As #handle

    FileText = Input$(LOF(handle), handle)

    Close #handle

End Function

 

Example calling code for this function:

 

Dim result as string

result=FileText("C:\MyFolder\MyFile.txt")

 

Example Subroutine to save a string to the text file:

 

Sub SaveText(textToSave as String, filename  as String)

    Dim fileNumber  as Integer

    fileNumber=FreeFile

    Open filename For Output As fileNumber

    Print fileNumber, textToSave

    Close fileNumber

End Sub

 

For example:

 

SaveText LString,"C:\MyFolder\MyFile.txt"

 

Obviously you need to change MyFolder and MyFile to something more meaningful and an existing folder on your computer.



-------------------------

Thanks Mark


 


Dragon Professional Advanced Scripting/KnowBrainer Scripts
Video Examples of Coding by Voice

 09/07/2019 03:50 PM
User is offline View Users Profile Print this message

Author Icon
Ag
Top-Tier Member

Posts: 1035
Joined: 07/08/2019

Ouch!

 

To persist a value between commands requires using an external database or a text file or the clipboard?

 

Here's how you do it in auto hotkey: two "commands" (hotkeys) defined by the same AHK file (actually instance, since an AHK instance can be spread across multiple files, and threads for that matter) share memory state.

 

CoordMode, Mouse, screen ; relative to screen not window
return

^!s::
mousegetpos,x,y
return

^!d::
mousemove,%x%,%y%
return

 

Save/restoring to the clipboard is not very useful for the reason I want this operation: the whole point is I want to jump back to a webpage, do some navigation and clip an item (like the micro USB cables I'm shopping for right now), jump back to my OneNote and paste the item, and continue. External database or text file will work, but it seems pretty darned heavyweight and probably slow.

 

 

In full detail

 

The AHK script Save-Restore-Mouse-Position.ahk

 

CoordMode, Mouse, screen ; relative to screen not window
return

;; Nice in itself for AHK
;; but especially useful when a Dragon speech command is bound to this
;; "Remember Mouse Position"
;; "Swap Mouse Position"

;; NOTE: the hack to do mousemove on a multi monitor system

^!+.::
   mousegetpos,saved_x,saved_y
   return

 

^!+,::
   mousegetpos,current_x,current_y
   ;mousemove,%saved_x%,%saved_y%
   ; https://www.autohotkey.com/docs/commands/MouseMove.htm
   ; the following is an alternate way to move the mouse cursor
   ;that may work better in certain multi-monitor configurations:

   DllCall("SetCursorPos", "int", saved_x, "int", saved_y)

   saved_x:=current_x
   saved_y:=current_y

   return

With Dragon commands 

Save Mouse Position ==> sending Ctrl+Shift+Alt period
Swap Mouse Position ==> sending Ctrl+Shift+Alt comma

 

It is unfortunate that Dragon SendKeys and AHK use different syntax, e.g. % vs ! for Alt.

 

 

I find this pattern of defining the basic function in AutoHotKey, with key bindings that Dragon/KnowBrainer can tickle, quite useful.  Partly because AHK's scripting language, although clumsy, seems more capable than Dragon/KnowBrainers.  But also because I often want to have keyboard shortcuts as well as voice shortcuts - I can still type, I just want to reduce the stress on my sore wrist/arm.

 

 

The biggest problem is that speech has high valency - you can have a very large number of commands - whereas hotkeys are much more limited. On Windows and MacOS, to the various combinations of modifiers and single keys.  I have previously created emacs-style menu systems for AHK, so that arbitrary length key sequences can be used to access AHK commands. I will look into automating so that Dragon/KnowBrainer commands can drive them.

 

 



-------------------------

DPG15.6 (also DPI 15.3) + KB, Sennheiser MB Pro 1 UC ML, BTD 800 dongle, Windows 10 Pro, MS Surface Book 3, Intel Core i7-1065G7 CPU @ 1.3/1.5GHz (4 cores, 8 logical, GPU=NVIDIA Quadro RTX 3000 with Max-Q Design.



 12/23/2020 10:49 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 1123
Joined: 11/05/2015

+1 for the KB Mouse Location command (again)! Every time (fairly rare) I need to make a mouse command for Dragon, I find myself booting up KB to take advantage of the Mouse Location command that puts the location on the clipboard ready for pasting into my Dragon script. It's just too easy. Thank you, Lindsay and Lunis!

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, excellent Sareville Wireless Mono Headset, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and Logitech G502 awesome gaming mouse.

Statistics
32529 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 2 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 435 guests browsing this forum, which makes a total of 437 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2023 FuseTalk™ Inc. All rights reserved.