moving mouse to MS word cursor position

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

moving mouse to MS word cursor position

10 Nov 2020, 06:23

this used to work to sync the mouse coordinate with the cursor position in MS word, but not since I moved to Office 10...I think....maybe because I am now on AHK v2....any ideas? Thank you

Code: Select all

Send, {Click, %A_CaretX%, %A_CaretY%}
gregster
Posts: 5836
Joined: 30 Sep 2013, 06:48

Re: moving mouse to MS word cursor position

10 Nov 2020, 07:37

Wouldn't this throw an error on AHK v2 anyway? At least in recent versions.

Did you look at v2's Send docs? (and the example Send "{Click 100, 200}" ?)
Also, I think the A_Caret variables were replaced with CaretGetPos().

Are you sure you are really running ahk v2 ? You are (not) aware of the many (breaking) changes?

I would expect something like

Code: Select all

CaretGetPos(x, y)
Send "{Click " x "," y "}"
but I am not very familiar with v2 yet.
User avatar
boiler
Posts: 6868
Joined: 21 Dec 2014, 02:44

Re: moving mouse to MS word cursor position

10 Nov 2020, 08:24

Verified that gregster's code works for me. I'm using the latest version of Office in Microsoft 365. I don't remember if Word in Office 2010 reported the caret position or not.
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

Re: moving mouse to MS word cursor position

11 Nov 2020, 07:22

Pretty sure I am on v2

I tried your code , Plugged it into my conversion app, And it converted successfully To the destination file. But I got this error message when I try to Invoke the new corrected ahk apartment

Error: call to nonexistent function

Specifically, CaretGetPos (x,y)

Sorry to be such a pain.
swagfag
Posts: 4138
Joined: 11 Jan 2017, 17:59

Re: moving mouse to MS word cursor position

11 Nov 2020, 07:36

then u arent running v2. u can check ur version with

Code: Select all

msgbox a_ahkversion
or(in case of v1, which u probably are running) with

Code: Select all

msgbox % a_ahkversion
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

Re: moving mouse to MS word cursor position

11 Nov 2020, 07:39

I don’t think I’m being clear. When I say Microsoft Word cursor I mean that blinking thingamabob on the page that tells you where, if you type, the line where the text will go. Even though the mouse pointer is somewhere else on the page.

Part of the code I am working on ends with moving the MS Word cursor down one line and a few spaces to the left. This, in order to allow me to re-invoke the same command (with the push of a key remapped by ahk) to start over again – and the beginning of the command is to left click twice in order to select the line where the MS Word cursor rests now. It’s really grabbing lines of numbers separated by hard returns, but for purposes of explanation assume it’s grabbing words from a Word document and pasting them one by one into another function:

Bobcat
Wildcat
Wombat

So the beginning of the app double-clicks, selects the line “Bobcat” copies it, and pastes the word into another function. Then the app switches screens and returns to the list and moves the MS Word cursor down to the middle of “wildcat” – the problem is that the mouse pointer keeps returning to a certain point somewhere else on the MS Word page – but the code that used to work had a line of code to move the mouse pointer to where the MS Word cursor is – and that MS cursor is on the word wildcat allowing me to serially grab words from the MS Word page and paste them, one by one, into the other application.

Here’s the full code that still mostly works but will not move the mouse pointer to where the word cursor is blinking – obviously from my ignorance I could not have written it myself without help from the good people on this forum.

Code: Select all

SetKeyDelay, 70 ;Sets the delay(Time in milliseconds) that will occur after each keystroke sent by Send and ControlSend. uncomment if something wrong
LWin::  ; Left windows key
clipboard = ; Empty the clipboard
Send {Click 2}
Send ^c
ClipWait 2 ; Waits 2 sec until the clipboard contains data.
Send !{Tab} ; Switch between the two most recent tasks (is it notepad?)
Sleep, 300
Send % StrReplace(clipboard,"-")
Sleep, 400
Send {Enter} ; new line
Sleep, 600
Send, {PGDN}
Sleep, 1800
Send, {ALTDOWN}{LEFT}{ALTUP}
Sleep, 500
Send !{Tab} ; Switch between the two most recent tasks (is it notepad?)
Sleep, 500
Send, {DOWN}{LEFT}{LEFT}{LEFT}{LEFT}
Send, {Click, %A_CaretX%, %A_CaretY%}
return
[Mod edit: [code][/code] tags added.]
User avatar
boiler
Posts: 6868
Joined: 21 Dec 2014, 02:44

Re: moving mouse to MS word cursor position

11 Nov 2020, 07:49

mikeahk wrote:
11 Nov 2020, 07:39
I don’t think I’m being clear. When I say Microsoft Word cursor I mean that blinking thingamabob on the page that tells you where, if you type, the line where the text will go. Even though the mouse pointer is somewhere else on the page.
We understand exactly what you mean and are talking about the same thing. And the following moves the mouse pointer to the blinking thingamabob on the Microsoft Word window on my machine:

Code: Select all

WinActivate, ahk_exe WINWORD.EXE
Send, {Click, %A_CaretX%, %A_CaretY%}
By the way that is v1 code. You are not using v2.
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

Re: moving mouse to MS word cursor position

11 Nov 2020, 08:08

Right. I honestly can't tell whether I'm on v1 or v2 – I created the ahk Application per Gregsters instructions and neither of them worked so I'm lost
User avatar
boiler
Posts: 6868
Joined: 21 Dec 2014, 02:44

Re: moving mouse to MS word cursor position

11 Nov 2020, 08:21

You are for sure using v1. The code swagfag posted will let you confirm it for yourself (run the v1 version because the v2 version will give you an error).

The code gregster posted will not work for you because that is v2 code. I don’t know what you mean by “neither of them worked.” I only see one script posted by gregster.

Did you run the code that I just posted? If that doesn’t work, it may be that Word 2010 doesn’t report the caret position, which doesn’t surprise me. I had it in my head that Word doesn’t report it, and I was surprised to find that mine did. I’m thinking I must have tried back when I had the 2010 version, and it didn’t work then.
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

Re: moving mouse to MS word cursor position

11 Nov 2020, 08:44

It’s working again and in fact it may have been working all along with the old v1 code – and I believe I am in version 1 – I think for the code to work properly I have to double mouse click at the top of the list and then it seems to work properly as it descends through the list. Don’t understand why. Probably never will. Sorry to have wasted your time.

Question – can you hire ahk experts to customize a code for you – I’m starting to think that, at age 60, I’m never really good to get the hang of this.
User avatar
boiler
Posts: 6868
Joined: 21 Dec 2014, 02:44

Re: moving mouse to MS word cursor position

11 Nov 2020, 09:04

You might find someone to help if you post a new topic in the main (not v2) section of Ask For Help titled "Looking to hire AHK coder" or something like that. The more detail you can provide on how large of an effort it is expected to be would help. I believe @Joe Glines offers his services on an individual basis, so you may want to contact him.
mikeahk
Posts: 20
Joined: 04 Nov 2017, 14:24

Re: moving mouse to MS word cursor position

11 Nov 2020, 10:10

I increased sleep intervals and that may have helped as well – thanks for all your help

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: Google [Bot], Pscyking and 2 guests