Page 1 of 1

double click after paste

Posted: 26 Sep 2016, 20:37
by mikagenic
I have the following script that selects the word at the cursor, pastes over it and then selects the current word

NumpadAdd::
CoordMode, Caret, Screen
CoordMode, Mouse, Screen
MouseGetPos, X_1, Y_1, ID_1, Control_1
MouseMove, %A_CaretX%, %A_CaretY% ; move mouse to caret pos
Click 2 ; select word
Send, ^v ; paste
Click 2 ; select word
MouseMove, %X_1%, %Y_1% ; restore mouse
Return

the paste happen correctly but the current word does not get selected
that is the second Click 2 does not work
why ? any help ?

Re: double click after paste

Posted: 26 Sep 2016, 21:07
by Exaskryz
Try slowing it down with a Sleep 100 before the second Click 2.

Re: double click after paste

Posted: 26 Sep 2016, 21:30
by mikagenic
I did, no luck even with a big sleep

Re: double click after paste

Posted: 26 Sep 2016, 22:40
by hunter99
Hi, If you want to select the word at the cursor, paste over it and then select the word you just pasted try this:
Change the 1st "Click 2" line to "send, ^+{right}" and the 2nd to "send, ^+{left}" no quotes.
If you want the word after the one you just pasted change the "^+{left}" to "^+{right}" no quotes.

hunter99

Re: double click after paste

Posted: 27 Sep 2016, 00:40
by mikagenic
hynter99, ctrl left right ietc s not what I want, it ends up selecting an extra space at the end of the word which is why the dbl click trick

But why is my code not working ?
why is the second Click 2 ignored ?

Re: double click after paste

Posted: 27 Sep 2016, 01:13
by Helgef
Perhaps the caret is placed after your word, try to subtract some pixels from the x-coord and perhaps add a few to the y-coord.

Re: double click after paste

Posted: 27 Sep 2016, 18:46
by mikagenic
thx Helgef, that didn't work, and also having the caret after the word should still highlight it on double click

Re: double click after paste

Posted: 28 Sep 2016, 03:22
by Helgef
This works for me in notepad++. I also added SetDefaultMouseSpeed,0, it is not needed if you don't want it.

Code: Select all

SetDefaultMouseSpeed,0
NumpadAdd::
CoordMode, Caret, Screen
CoordMode, Mouse, Screen
MouseGetPos, X_1, Y_1, ID_1, Control_1 
Click %A_CaretX%, %A_CaretY%,2 ; select word
Send, ^v ; paste
x:=A_CaretX-5
y:=A_CaretY+5
Click %x%, %y%,2 ; select word
MouseMove, %X_1%, %Y_1% ; restore mouse 
Return
If you have problems, try adding a sleep as suggested earlier. Note that the caret positions are not reported accurately by all windows.

Re: double click after paste

Posted: 28 Sep 2016, 21:48
by mikagenic
works great ! thanks you