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
 How to remember mouse position and return to it?   - avkatz - 01/05/2018 06:04 PM  
 How to remember mouse position and return to it?   - Lunis Orcutt - 01/05/2018 06:34 PM  
 How to remember mouse position and return to it?   - avkatz - 01/05/2018 06:53 PM  
 How to remember mouse position and return to it?   - avkatz - 01/05/2018 06:57 PM  
 How to remember mouse position and return to it?   - Grindcore - 01/05/2018 10:26 PM  
 How to remember mouse position and return to it?   - avkatz - 01/06/2018 10:02 AM  
 How to remember mouse position and return to it?   - Mark Bennett - 06/01/2018 04:51 PM  
 How to remember mouse position and return to it?   - Mphillipson - 06/03/2018 03:46 PM  
 How to remember mouse position and return to it?   - Ag - 09/07/2019 03:50 PM  
 How to remember mouse position and return to it?   - barrysingh102 - 11/19/2019 09:04 AM  
Keyword
 01/05/2018 06:04 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 7
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: 37356
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”.



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

Forum Mission Statement
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ext 1

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

Author Icon
avkatz
New Member

Posts: 7
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: 7
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: 7
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
Advanced Member

Posts: 194
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: 326
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.5 (also DPI 15.3) + KB, Sennheiser MB Pro 1 UC ML, BTD 800 dongle, Windows 10 Pro, Dell Inspiron 7591 2-in-1, 64GB RAM, Intel Corei7-10510U CPU @ 1.80GHz, 2304 Mhz, 4 Cores...




 11/19/2019 09:04 AM
User is offline View Users Profile Print this message

Author Icon
barrysingh102
New Member

Posts: 1
Joined: 11/19/2019

please check help file on Hotkey, MouseGetPos, and MouseMove
example:
a:
mousegetpos,x,y
return

b:
mousemove,%x%,%y%
return 

Shareit apk Vidmate app



Statistics
31556 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 1 users logged in.
The most users ever online was 3936 on 09/08/2015 at 11:44 AM.
There are currently 315 guests browsing this forum, which makes a total of 316 users using this forum.

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