How to Copy Word, Move Mouse to Previous word?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Vaklev
Posts: 47
Joined: 04 Mar 2019, 13:58
Contact:

How to Copy Word, Move Mouse to Previous word?

Post by Vaklev » 29 Aug 2019, 12:36

Hi guys, I am double clicking to highlight words and copy them, lets say I am copying the following:

Ivan Yordanovitch Petrov

I will start from right to left, move my mouse over the word Petrov, send a copy script, then I want to move the mouse to the word prior "Yordanovitch", and then copy that and repeat the same and move the mouse to Ivan, now, the data always varries, sometimes I get 4 names, sometimes 6 or 2, and the lenght is always different, is there a way to identify the space between the words, and send the mouse maybe 5-6 pixels left of the spacing between words?

Maybe a different solution would be if there is a way to copy the entire phrase, and identify the amount of words there are based on spaces and have them each copy and paste into different coordinates?

Current code, I have hard coded the paste coordinates:

Code: Select all

f1:: ; LAST NAME
MouseClick left	
MouseClick left
Send {LControl Down}c{Lcontrol Up}
sleep 100
MouseMove 267,413
MouseClick left
Send {LControl Down}v{Lcontrol Up}
Mousemove, 132,232
return

+2:: ; FIRST NAME  double click
MouseClick left
MouseClick left
Send {LControl Down}c{Lcontrol Up}
MouseMove 505,412
MouseClick left
MouseClick left
MouseClick left
Send {LControl Down}v{Lcontrol Up}
Mousemove, 134,239
return

f2:: ; FIRST NAME DRAG
Send {lbutton down} ; holds left click
MouseMove -100,0,10,r ; 
Send {lbutton up} ;
Send {LControl Down}c{Lcontrol Up}
sleep 100
MouseMove 505,412
MouseClick left
MouseClick left
MouseClick left
Send {LControl Down}v{Lcontrol Up}
Mousemove, 134,239
return

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to Copy Word, Move Mouse to Previous word?

Post by Rohwedder » 30 Aug 2019, 00:57

Hallo,
maybe this will help:

Code: Select all

ClipBoard = Ivan Yordanovitch Petrov
;copy the entire phrase

ClipBoard := RegExReplace(Trim(ClipBoard),"\s+"," ")
Sort, ClipBoard, F Revers D%A_Space%
Revers(a1,a2,offset){
	return offset
}
StringSplit, Word, ClipBoard, %A_Space%
;any number of words in reverse order:

MsgBox,% "last word: " Word1
MsgBox,% "second to last word: " Word2
; ...
MsgBox,% "first word: " Word%Word0%

awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: How to Copy Word, Move Mouse to Previous word?

Post by awel20 » 30 Aug 2019, 10:33

Here's another attempt at helping.
Highlight all the words and then press F1.

Code: Select all

; Put this at the top of your script before the first return or hotkey
; these values will be the mouse coordinates for each paste
; {x:267, y:413} is for the first paste, {x:505, y:412} is for the second paste...
; add more coordinates as required
MousePoints := [{x:267, y:413}, {x:505, y:412}, {x:100, y:200}]
arrCopied := []
MsgBox Highlight some words and press F1 to copy new words.
return

; Highlight words and press F1. Then press F1 again to paste
F1::
	if (arrCopied.MaxIndex() = "")
	{
		Clipboard := ""
		Send, ^c
		ClipWait, 1
		Copied := Trim(Clipboard)
		arrCopied := StrSplit(Copied, " ")
		WordNumber := 1
		MsgBox % "Copied words:`n`n" Clipboard
	}
	else
	{
		Clipboard := arrCopied.Pop()
		MouseMove, % MousePoints[WordNumber].x, % MousePoints[WordNumber].y
		MouseClick Left
		Send, ^v
		WordNumber++
		if (!arrCopied.HasKey(1))
			MsgBox Last word reached. Highlight some words and press F1 to copy new words.
	}
return
Instead of clicking the mouse and pasting, it might be better to use ControlSetText, ControlSend, etc. It might not work depending on the program that you are sending text to. If Window Spy can read some info about the individual controls then there is a good chance that the Control-type commands will work (right click on the tray icon of a running AHK script and select "Window Spy") .

Post Reply

Return to “Ask for Help (v1)”