 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
complx Guest
|
Posted: Fri Aug 03, 2007 6:50 pm Post subject: Click-function doesn't change caret to given position |
|
|
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
|
Posted: Fri Aug 03, 2007 8:35 pm Post subject: |
|
|
maybe you should use
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 |
|
 |
complx Guest
|
Posted: Sat Aug 04, 2007 9:11 am Post subject: |
|
|
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
|
Posted: Sat Aug 04, 2007 9:28 am Post subject: addendum |
|
|
Hi,
just had a try with mouseclick. Changing Click to MouseClick has the desired effect.
Can anybody explain?
Thx,
complx |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Sun Aug 05, 2007 4:31 am Post subject: |
|
|
| 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 |
|
 |
complx Guest
|
Posted: Sun Aug 05, 2007 8:41 am Post subject: |
|
|
| 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
|
Posted: Sun Aug 05, 2007 10:14 am Post subject: |
|
|
| 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 |
|
 |
complx Guest
|
Posted: Tue Aug 07, 2007 7:44 am Post subject: |
|
|
| 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.
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
|
Posted: Tue Aug 07, 2007 9:11 am Post subject: |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Aug 07, 2007 12:57 pm Post subject: |
|
|
| I've added an example to the top of the Click page that demonstrates the use of percent signs. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Tue Aug 07, 2007 5:26 pm Post subject: |
|
|
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 |
|
 |
epiphysis
Joined: 04 Jan 2008 Posts: 1 Location: Washington State
|
Posted: Fri Jan 04, 2008 9:07 am Post subject: |
|
|
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 |
|
 |
Robfm
Joined: 27 Dec 2007 Posts: 20 Location: Brazil
|
Posted: Thu Feb 07, 2008 10:15 pm Post subject: Studing Caret position. |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|