AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Click-function doesn't change caret to given position

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
complx
Guest





PostPosted: Fri Aug 03, 2007 6:50 pm    Post subject: Click-function doesn't change caret to given position Reply with quote

Hi,

I encountered a possible bug when using the click function to change the carets position.

This is what I try to achieve (expected result):
* store the caretīs position.
* do some changes to a current controls text using copy&paste
* restore the caretīs previous position cause it was changed by the paste-operation

Code:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

CoordMode, Caret, Relative
CoordMode, Mouse, Relative

; store cursorīs current position
x := A_CaretX
y := A_CaretY
;MouseGetPos, mouseX, mouseY  ; [x]

; [...]
; do some text manipulation
; paste text back to the current control
; which changes cursor position to the last line of the pasted text-block
; [...]

; set cursor back to previous position

click x, y
;click mouseX, mouseY ; [x]

return


This is what actually happens:
Instead of moving the caret to the position saved before the click operation moves the caret to the currentīs mouse-pointer position as if I used the commented lines marked with an [x].

To reproduce use the code given above. Open notepad insert 10 lines, move the mouse-pointer above line 10, move the caret into line 3 using the keyboard. Execute the script. Caret will move to line 10, not to line 3 as the code would suggest.

Am I overlooking something? Any hint will be appreciated.

TIA,
complx

Reproduced with AutoHotkey version 1.0.46.17 and 1.0.47.03;
Win2000 and WinXP using different editors
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Fri Aug 03, 2007 8:35 pm    Post subject: Reply with quote

maybe you should use
Code:

click %x%, %y%


since x and y are variables.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
complx
Guest





PostPosted: Sat Aug 04, 2007 9:11 am    Post subject: Reply with quote

Hi,

sorry but the enclosion in percent signs makes no difference and according to the documentation this should not be necessary. Or are there any exceptions for some functions I've to consider?

Thx,
complx
Back to top
complx
Guest





PostPosted: Sat Aug 04, 2007 9:28 am    Post subject: addendum Reply with quote

Hi,

just had a try with mouseclick. Changing Click to MouseClick has the desired effect.
Code:
MouseClick, , x, y


Can anybody explain?

Thx,
complx
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Sun Aug 05, 2007 4:31 am    Post subject: Reply with quote

complx wrote:
according to the documentation this should not be necessary


where does it say that?
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
complx
Guest





PostPosted: Sun Aug 05, 2007 8:41 am    Post subject: Reply with quote

Quote:
where does it say that?

See FAQ/Language Syntax Section "When are quotation marks used with commands and their parameters?"
Quote:
Variable names are always enclosed in percent signs except in cases illustrated in bold below:

1) In parameters that are input or output variables: StringLen, OutputVar, InputVar[...]


But thatīs not the core problem, isnīt it. Furthermore it makes no difference, at least in my tries. Is there a change when you use percent signs??

Again can anybody reproduce the behavior described above?

Thx a lot,
complx
Back to top
YMP



Joined: 23 Dec 2006
Posts: 265
Location: Russia

PostPosted: Sun Aug 05, 2007 10:14 am    Post subject: Reply with quote

complx wrote:

Is there a change when you use percent signs??

Yes, putting x and y in percent signs makes your script work.

According to what the manual says, coordinates for MouseClick can be expressions (i.e. don't require percent signs), while coords for Click can not.
Back to top
View user's profile Send private message
complx
Guest





PostPosted: Tue Aug 07, 2007 7:44 am    Post subject: Reply with quote

Quote:
Since click does not support expressions, variables should be enclosed in percent signs.
RTFM. Damn! I overlooked the small print.

Yes it works! I would have sworn I tested this, perhaps I only used on %-sign, I don't know. Embarassed Embarassed

It would be nice to have a little footnote in the FAQ-section mentioned before, that NOT ALL functions allow unquoted input variables.

Sorry for bothering you and thx again!
complx
Back to top
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Tue Aug 07, 2007 9:11 am    Post subject: Reply with quote

The section you quoted actually explains it.

Anywhere that is an input or output variable.

click uses numbers to determine coordinates not variables.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Aug 07, 2007 12:57 pm    Post subject: Reply with quote

I've added an example to the top of the Click page that demonstrates the use of percent signs.
Back to top
View user's profile Send private message Send e-mail
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Tue Aug 07, 2007 5:26 pm    Post subject: Reply with quote

Thanks Chris, I felt that was lacking when trying to explain this. Never got around to asking for it.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
epiphysis



Joined: 04 Jan 2008
Posts: 1
Location: Washington State

PostPosted: Fri Jan 04, 2008 9:07 am    Post subject: Reply with quote

Hi,

I'm new to the forum. I've bumped this older thread because I am experiencing exactly the same problem originally described here.

I've read all of the responses above, and I appreciate Chris's examples and clarifications on the Clicks page. Unfortunately, the problem seems to still persist, and I think it may need some further investigation.

From the responses above, it isn't clear to me that anyone has actually duplicated the caret behavior that the original poster described. So, I just wanted to say that I have.

My script is written for MS Word 2003 running on Vista. I know there are issues with some editions of Word, so I've run the tooltip script shown on the "Variables and Expressions" page to make certain that Word reports the caret position as it moves around. (It does.) I have also duplicated the same problem behavior in Windows Notepad running on Vista.

At this point, it seems to me that it really doesn't matter if the line is written --

Click %x%, %y%
--or--
Click x, y

In either case, the caret lands wherever it wants, and that is usually at the end of the document. Sometimes, it lands directly on top of the mouse cursor.

The original poster (complx) said that adding the percent signs around the x-y variables solved his problem. If he is still reading the forum, I would like to know if the problem reappeared later. I would also appreciate anyone's thoughts or suggestions for a workaround that I could use temporarily to restore the caret to its original position.
Back to top
View user's profile Send private message
Robfm



Joined: 27 Dec 2007
Posts: 20
Location: Brazil

PostPosted: Thu Feb 07, 2008 10:15 pm    Post subject: Studing Caret position. Reply with quote

To study...


Code:
#Persistent
; Obs.: A_CaretX and A_CaretY, are not functional on Firefox and some other softwares.

Line1:
  KeyWait, LButton,  D

  ;CoordMode, Caret, Screen        ; Study the difference with and without this line.
  CharacterInX = %A_CaretX%
  CharacterInY = %A_CaretY%

ToolTip, The insertion point is at:`nX = %CharacterInX%`nY = %CharacterInY%, CharacterInX, CharacterInY - 20

; Or Simply :
;ToolTip, The insertion point is at:`nX = %A_CaretX%`nY = %A_CaretY%, A_CaretX, A_CaretY - 20

; Note, at above line, A_CaretX and A_CaretY - 20 are the x,y coordenates where ToolTip will splash.
Goto Line1
return

_________________
The humanity is the Evolution taking consciousness of itself.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group