![]() |
KnowBrainer Speech Recognition | ![]() |
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 |
|
![]() |
![]() |
- brainerfan | - 11/12/2021 07:23 AM |
![]() |
![]() |
- Edgar | - 11/12/2021 11:30 AM |
![]() |
![]() |
- brainerfan | - 11/23/2021 04:52 AM |
![]() |
![]() |
- Edgar | - 11/23/2021 12:04 PM |
![]() |
![]() |
- Edgar | - 11/23/2021 04:28 PM |
![]() |
|
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! |
|
|
|
![]() |
|
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 windowX = Str (z.x) windowY = Str (z.y) clip = "SendKeys "ClickLeft " & windowX & ", " & windowY
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 |
|
|
|
![]() |
|
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?
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. |
|
|
|
![]() |
|
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 |
|
|
|
![]() |
|
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). 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 |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2023 FuseTalk™ Inc. All rights reserved.