Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Get current non-mouse cursor position


  • Please log in to reply
10 replies to this topic
dsavant
  • Members
  • 562 posts
  • Last active: May 23 2016 01:14 AM
  • Joined: 04 Aug 2009
Hello,

I know how to get the current mouse cursor position and get back to it by using:

CoordMode, Mouse, Screen
MouseGetPos px,py
.
.
.
.
CoordMode, Mouse, Screen
MouseMove %px%,%py%

However, since the cursor position for where I am actually entering data at any given time may be different than the mouse cursor position, is there a way to capture that data entry position so I can get back there after running a thread of commands?

For example, suppose I am in Excel and MouseClick cell B2 then (with no further mouse movement), I type:

2 > Enter > 3 > Enter > 4 > Enter > 5 > Enter > 6 > Enter > 7

So now, although the mouse cursor position is still at cell B2 I am actually typing in cell B7. Is there a way to capture the B7 position so I can get back there after the macro runs?

Thanks

avant ds
  • Guests
  • Last active:
  • Joined: --
A_CaretX
A_CaretY


dsavant
  • Members
  • 562 posts
  • Last active: May 23 2016 01:14 AM
  • Joined: 04 Aug 2009
Thanks for the reply but could you give a bit more info? I've tried what you posted several ways but it is not working.

For example, what would the

GetPos

and

MouseMove

code lines be and what, if any, other code is needed?

Thanks

avant ds
  • Guests
  • Last active:
  • Joined: --
please read the manual for A_CaretX

dsavant
  • Members
  • 562 posts
  • Last active: May 23 2016 01:14 AM
  • Joined: 04 Aug 2009
OK, I understand that A_CaretX and A_CaretY refer to:

The current X and Y coordinates of the caret (text insertion point).

The problem is that I don't know how to capture those coords so they can be used in a future command. I assume it's a WinGet or GetPos command but I can't determine which and how to write it.

R/T/F/M
  • Guests
  • Last active:
  • Joined: --
Just use them; they're built-in variables. As soon as they're called in your code, the active insertion point is stored.

MsgBox, %A_CaretX%  %A_CaretY%


DarkVamprism
  • Members
  • 125 posts
  • Last active: Apr 25 2017 10:28 AM
  • Joined: 03 Sep 2009
I don't think you guys get what he means....

Does it matter if it moves to the required position for a little while?
so like this.

#c::MouseGetPos , posX , posY
#v::MouseMove , %posX% , %posY%

basically a copy paste for your mouse

trenton_xavier
  • Members
  • 82 posts
  • Last active: Mar 16 2012 11:25 AM
  • Joined: 16 Jun 2008
Um, I think he's looking for this:

MouseMove, %A_CaretX%, %A_CaretY%

This will move your mouse cursor to the current insertion point of excel (or whatever app)

DarkVamprism
  • Members
  • 125 posts
  • Last active: Apr 25 2017 10:28 AM
  • Joined: 03 Sep 2009
Sorry your right, I haven't really been thinking, maybe I'll stop posting tonight, thats the second mistake I've made lol :oops:

jonathan scott james
  • Members
  • 24 posts
  • Last active: May 04 2018 03:25 PM
  • Joined: 23 Feb 2015

if he's like me. he wants to find the carrot position then search for text starting at that point then if there's another match, start at that point abs search for the successive match,, then maybe re-position the cursor and search for something else starting near or at that last found text depending if the text has been edited (which would move the carrot)

 

Gui, Add, Edit, hwndhEdit1 vMainEdit w600 R20
Gui, Show,,
FileRead, MainEdit, sometextfile.txt
GuiControl,, MainEdit, %MainEdit%
 
^f::
inputbox,findthis,find text,%findthis%
lenfindthis=StrLen(findthis)

 

startpos=****~unknown_current_position_of_carrot what goes here?~****

foundit:=instr(mainedit,findthis,startpos)

startpos:=foundit+1
SendMessage, 0xB1, foundit, foundit,, ahk_id %hEdit1% 

SendInput, {left}{shift down}{right %lenfindthis%}{shift up}sendinput{shift down}{right %lenfindthis%){shift up}

return

 

thats prolly not right. but you get the picture.. the user is at will to edit the text in the edit and move the carrot so you have to fiugure out the posityion of the carrot before you instigate the next find opperation because it has to start at the new posirtion of the cursor, not just where it last positionned the carrot at the last find.... p.s., the only way i can imagine is read the carrot x,y, then take a guess at where the carrot is then position the carrot there and determine if its before or after the actual place . then reposition it in the direction and determine if it went past or not then poke and peek again and again 64 times till you narrow it to one ourt of a trillion bytes. lol. please help. 



zloidooraque
  • Members
  • 7 posts
  • Last active: Jan 01 2016 12:54 PM
  • Joined: 20 Aug 2015

 

 

he wants to find the carrot position then search for text starting at that point then if there's another match, start at that point abs search for the successive match,, then maybe re-position the cursor and search for something else starting near or at that last found text depending if the text has been edited (which would move the carrot)

 

i don't understand the scenario. 

what does you need it for?

i actualy dont understand what it does..