KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Help with writing commands calling MousePosition on multiple monitors?
Topic Summary:
Created On: 11/10/2021 05:48 PM
Status: Post and Reply
Linear : Threading : Single : Branch
Keyword
 11/10/2021 05:48 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 11
Joined: 01/05/2018

I have a set of commands that allow me to mechanize various editing commands in a PDF editing program, and that are based on moving the mouse to a particular location on the screen.  For example, if I wish to change the color of the highlighter pen to yellow, I need to click on a  particular spot on the screen.     But the coordinates of this spot are different depending upon which computer monitor I happen to be using.

Is it possible for me to create a variable consisting of an ordered triple that would depend on which computer or monitor I'm using.  For example, it could be called YellowMousePosition, and its content would differ depending upon the monitor.  And then I could just set the mouse position by saying something like "SetMousePosition YellowMousePosition".

This is got to be possible, right?  Or is there a more straightforward solution that just scales all mouse position calls depending upon the monitor, so I don't have to create YellowMousePosition, BlueMousePosition, etc.?

Thanks, Avery

 



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

Avery 

 11/10/2021 07:27 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 40203
Joined: 10/01/2006

KnowBrainer 2020 includes the Find Mouse Position command. Just say this command to capture your mouse X & Y window coordinates. The following command works in both KnowBrainer 6 - 2020 and Dragon

 

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

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
clip = clip & Chr(13) & Chr(10) & _
"Wait 0.5" & Chr(13) & Chr(10) & _
"ButtonClick 1,1" & Chr(13) & Chr(10) & _
"Wait 0.5" & Chr(13) & Chr(10)
'
Clipboard clip
'
TTSPlayString "ready"
End Sub


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

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



 11/10/2021 08:34 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 11
Joined: 01/05/2018

Thanks. I know about the Find Mouse Position and have been using it. That's how I found the original set of coordinates. But I was hoping that there was a simple method to translate commands written to work on one monitor so that they would work on another monitor, without having to collect and paste in all the new mouse positions all over again for the new monitor.

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

Avery 

 11/11/2021 10:38 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2219
Joined: 03/21/2007

Of course you can. You can use math to calculate since you can find the offset (monitors start at adjoining and adjacent pixels) which is constant (so addition or subtraction) and you can find the resolution, scaling and DPI factors of each monitor display to determine the ratio of unit lengths (so division) which can help you with determining the number of units lengths in the x and y direction to get to your spot of interest (so multiplication). It is not as hard as you'd think, but for more help look for the "Fling" AHK command I once wrote (and still use) which takes a program window from one monitor and positions it on another monitor in the exact same relative position and size as originally (and accounting for the different resolution and scaling of the different monitor) from which you can find most of the math involved: here

Good luck, I have found those attempts at locating buttons that way mostly futile (as applications don't draw UI based only on resolution and scaling, etc.), save for the overall window position containing the UI. For pdfs, look up the shortcut keys and use them. In worse cases, you can march through menu structures with keyboard access (alt-keys) and for example I have created scripts for PDF-XChange that cover things like highlight color or picking other commenting tools, etc. by doing just that: here

Hth,



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




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 11/12/2021 03:00 PM
User is offline View Users Profile Print this message

Author Icon
avkatz
New Member

Posts: 11
Joined: 01/05/2018

Thanks much - this is a help. With regard to using shortcut keys, I do that when feasible, but I am using Fox it PDF Editor, which is based on a graphic interface and does not (as far as I know) allow me to choose color and similar features using a keyboard. Maybe I should switch to PDF-XChange.

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

Avery 

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

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