![]() |
KnowBrainer Speech Recognition | ![]() |
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 |
|
![]() |
![]() |
- avkatz | - 01/05/2018 06:04 PM |
![]() |
![]() |
- Lunis Orcutt | - 01/05/2018 06:34 PM |
![]() |
![]() |
- avkatz | - 01/05/2018 06:53 PM |
![]() |
![]() |
- avkatz | - 01/05/2018 06:57 PM |
![]() |
![]() |
- Grindcore | - 01/05/2018 10:26 PM |
![]() |
![]() |
- avkatz | - 01/06/2018 10:02 AM |
![]() |
![]() |
- Mark Bennett | - 06/01/2018 04:51 PM |
![]() |
![]() |
- Mphillipson | - 06/03/2018 03:46 PM |
![]() |
![]() |
- Ag | - 09/07/2019 03:50 PM |
![]() |
![]() |
- kkkwj | - 12/23/2020 10:49 PM |
![]() |
|
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 |
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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
|
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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. ------------------------- Mark Bennett, Learning about Computer Disability Accomodations |
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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
With Dragon commands
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. |
|
|
|
![]() |
|
+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. |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2023 FuseTalk™ Inc. All rights reserved.