KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Is there a "SendKeys {ClickLeft x,y}" style "Code" command ...
Topic Summary: Need help.
Created On: 11/12/2021 07:23 AM
Status: Post and Reply
Linear : Threading : Single : Branch
 11/12/2021 07:23 AM
User is offline View Users Profile Print this message

Author Icon
brainerfan
New Member

Posts: 12
Joined: 10/03/2021

So I basically want a voice command to get the "{ClickLeft x,y}" of my current mouse location, to simplify when I make left/right click commands and make them faster, without having to deal with the "Wait" & "SetMousePosition" parts.

 

Is there an existing "Code" command or something that does this? And if not, how would I make it?

 

I'd ideally want it work similar to a "Code "-type command, but have it write the current mouse location in a "SendKeys "{ClickRight x,y}"" format (for when making a new KnowBrainer voice command), but I'm not sure how I'd do that.

 

Any help would be appreciated!



 11/12/2021 11:30 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1276
Joined: 04/03/2009

First, I don't think you actually want your new command to write the new "SendKeys…" line. You will probably want the line placed on the clipboard for you to paste where appropriate. Next, you'll probably need 2 commands - one will be for window-specific location and the other for screen-specific location. Finally, you will need to use a couple of Windows-API "things". These will need to be Advanced Scripting commands. Here is an untested example of how a screen-version might look (name it what you will):

 

 

Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINT) As Long

Type POINT

   x As Long

   y As Long

End Type

 

Sub Main

   Dim z As POINT

   GetCursorPos z

   clip = "SendKeys "ClickLeft " & z.x & ", " & z.y

   clip = Replace (clip, "  ", " ")' might be unnecessary

   Clipboard clip

 

End Sub

You might need to convert the numeric values:

   windowX = Str (z.x)

   windowY = Str (z.y)

   clip = "SendKeys "ClickLeft " & windowX & ", " & windowY

For reference, here's how you get the window-specific coordinates:

 

Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As LOCATIONSIZE) As Long

Type LOCATIONSIZE

   Left As Long

   Top As Long

   Width As Long

   Height As Long

End Type

 

Function GetWinCurPos(hwnd As Long) As POINT

   Dim point As POINT

   Dim windowSizeAndLocation As LOCATIONSIZE

   Dim result As POINT

 

   GetCursorPos point

   GetWindowRect hwnd, windowSizeAndLocation

   result.x = point.x - windowSizeAndLocation.Left

   result.y = point.y - windowSizeAndLocation.Top

   GetWinCurPos = result

End Function

 

Sub Main

   Dim hwnd As Long

   Dim result As POINT

   Dim clip, preface, yString, middle, message As String

 

   hwnd = GetForegroundWindow

   result = GetWinCurPos(hwnd)

   clip = "SetMousePosition 1, " & result.x & ", " & result.y

   clip = Replace (clip, "  ", " ")

   preface = "The captured window-relative mouse position was: X = "

   Dim xString As String

   xString = Str (result.x)

   yString = Str (result.y)

   middle = " Y = "

   message = preface+xString+middle+yString

   MsgBox message, 0, "Mouse Window Position"

   Clipboard clip

End Sub



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

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 11/23/2021 04:52 AM
User is offline View Users Profile Print this message

Author Icon
brainerfan
New Member

Posts: 12
Joined: 10/03/2021

Thanks for the reply! 

So I was trying to get it to work, and pasted this in:

 

Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINT) As Long
Type POINT
   x As Long
   y As Long
End Type
 
Sub Main
   Dim z As POINT
   GetCursorPos z
   clip = "SendKeys "ClickLeft " & z.x & ", " & z.y
   clip = Replace (clip, "  ", " ")' might be unnecessary
   Clipboard clip
 
End Sub


...But I don't fully understand the last bit?

You might need to convert the numeric values:

   windowX = Str (z.x)

   windowY = Str (z.y)

   clip = "SendKeys "ClickLeft " & windowX & ", " & windowY

 

 

I ended up getting an error on line 10, but I'm afraid I'm still very new to this and am not sure what to change... 

Would it be possible for you to explain that last bit? Would really appreciate it.



 11/23/2021 12:04 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1276
Joined: 04/03/2009

Type POINT

   x As Long

   y As Long

End Type

Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINT) As Long

 

Sub Main

   Dim z As POINT

   Dim clip, windowX, windowY As String

 

   GetCursorPos z

   windowX = Str (z.x)

   windowY = Str (z.y)

   clip = "SendKeys "

   clip = clip & """

   clip = clip & "{ClickLeft " & windowX & ", " & windowY & "}

   clip = clip & """

   clip = Replace (clip, "  ", " ")' might be unnecessary

   Clipboard clip

End Sub



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

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 11/23/2021 04:28 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1276
Joined: 04/03/2009

Sorry I did not present any explanation with the above code but I was late for an appointment. Some things to consider: I compiled and tested this with DPI 15.3; the exact string might not be exactly what you are looking for (I'm a bit confused about your requirements).

I ended up using the

   windowX = Str (z.x)

constructs; the concept here is that z.x is an integer variable and we need a string (windowX) when we build up our "clip" variable (some Basics will do this automatically as I attempted in my first example). I built up the "clip" variable using a number of separate statements because I could not get it to compile as a single statement <shrug>.



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

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

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

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