Copying highlighted text in Acrobat to different window in MS Word...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NYJack
Posts: 8
Joined: 12 Dec 2020, 20:43

Copying highlighted text in Acrobat to different window in MS Word...

28 Jan 2021, 23:46

Copying highlighted text in Acrobat to different window in MS Word...

Good Evening, Here is my script, which is not working. I humbly ask for your assistance in order to save my wrist.

Code: Select all

#5:: ;copy cursor-highlighted text to clipboard in Acrobat, go to and paste in window containing MS Word, add 2 returns, return to Acrobat
Send, {CTRL}c{CTRLUP}
Send, {ALTDOWN}{TAB}{ALTUP}
Send, {CTRL}v{CTRLUP}
Send, {ENTER}{ENTER}
Send, {ALTDOWN}{TAB}{ALTUP}
return
[Mod edit: [code][/code] tags added.]
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Copying highlighted text in Acrobat to different window in MS Word...

28 Jan 2021, 23:52

You need a space between the key name and DOWN or UP. Also, you are not always sending DOWN, so it would be immediately released.
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Copying highlighted text in Acrobat to different window in MS Word...

29 Jan 2021, 03:39

I would suggest using ^c and ^v instead of the keyname plus down or up; and also to add a sleep or clipwait after sending ^c.

Instead of using alt-tab you can use winactivate, so Adobe and Word don't need to be next to each other in your Z-stack (say in case you manually alt-tab to something else in between copying stuff).
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Copying highlighted text in Acrobat to different window in MS Word...

29 Jan 2021, 03:43

boiler wrote:
28 Jan 2021, 23:52
You need a space between the key name and DOWN or UP.
I don't think that's true. It should work with or without space between {keyname} and key.
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Copying highlighted text in Acrobat to different window in MS Word...

29 Jan 2021, 07:18

Pepineros wrote:
29 Jan 2021, 03:43
boiler wrote:
28 Jan 2021, 23:52
You need a space between the key name and DOWN or UP.
I don't think that's true. It should work with or without space between {keyname} and key.
I never knew that. However, the point about not having DOWN with some of the keys is still valid because it would release the key (essentially perform a down and up) before sending the next key.
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Copying highlighted text in Acrobat to different window in MS Word...

29 Jan 2021, 07:19

Pepineros wrote:
29 Jan 2021, 03:39
I would suggest using ^c and ^v instead of the keyname plus down or up
Since he already has the key names, I would leave them. It is more reliable.
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Copying highlighted text in Acrobat to different window in MS Word...

30 Jan 2021, 08:02

boiler wrote:
29 Jan 2021, 07:18
...the point about not having DOWN with some of the keys is still valid because it would release the key (essentially perform a down and up) before sending the next key.
Absolutely! You fixed OP's script. Shame they didn't reply.
NYJack
Posts: 8
Joined: 12 Dec 2020, 20:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 11:32

Good morning, I'm back online and will try script and report. It did not go back onto MS Word with ALT TAB, so Winactivate is what I'll use next, I do appreciate you all and hope one day to be a giver (as well as taker). Thanks more than you know.

Best, Jack
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 15:08

@NYJack i hope this help u .

Code: Select all

#5::WordPasteAtSelection()

WordPasteAtSelection()
{
    ClipSaved := ClipboardAll
    Clipboard := ""
    Send, ^c
    ClipWait, 1, 1
    oWord := ComObjActive("Word.Application")
    oWord.Visible :=	1, oWord.Activate
    oWord.Selection.PasteAndFormat(16)
    Clipboard := ClipSaved
    return
}
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 16:57

@NYJack here is another example of pasting into Word through COM to avoid the window switching.

Code: Select all

wdApp := ComObjActive("Word.Application")

f1::
	wdApp.Selection.PasteAndFormat(16) ; Original Formatting
return

f2::
	wdApp.Selection.PasteAndFormat(22) ; Plain Text
return

F3::
	wdApp.Selection.PasteAndFormat(0) ; Default 
return

Esc::ExitApp
If you have the full version of Acrobat then you can also use COM to get the highlighted text without having to use key sends and window tabbing which can be unreliable.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
NYJack
Posts: 8
Joined: 12 Dec 2020, 20:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 19:29

Hello all and thanks so much for the interest in helping.

I neglected to say that I am using two monitors when I'm doing what I wish to doing better and easier, with open MS Word on the left and open Acrobat DC on the right.

So what did I just notice? Upon highlighting text in Acrobat on the right, I can do an easy drag into Word on the left...

Point: it comes into Word as Courier Bold (size 10) type when it supersedes type set to Calibri (size 11), which I'd set formatting as for all text.

But I had an epiphany: might there be a way to highlight text and, as soon as I let go of the highlighting left mouse button (keeping the text highlighted), a script is triggered (by letting go of the left mouse button) -- the highlighted text is dropped at the bottom of the Word file AND two returns in Word are typed?

In this way, I never leave Acrobat. I simply click on the next result of an Acrobat Search (in the floating search bar), see if I wish to keep the the resulting informational text and highlight if I do...triggering again its being copied to Word, with two spaces thereafter!
NYJack
Posts: 8
Joined: 12 Dec 2020, 20:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 20:31

So, looking at both HiSoKa's and FanaticGuru's code . . . I can learn from each of you.

I changed WinKey-5 to F5 as the trigger in Acrobat DC to copy the highlighted text to the open MS Word file's bottom [this takes needing to hit two keys down to only one, major work savings when I do 300-to-400 records daily]. I tried but don't know where to place {ENTER}{ENTER} to add the two blank lines to the bottom of the text...

From FanaticGuru's code, I see that we can have the incoming text formatted to "Default," hopefully meaning it can be Calibri (Body) in 11 point size, or the default for this file...

To sum it all up, if I could have highlighted text from Acrobat land in formatted fashion in Word, with two returns added to the bottom, that will save me at least one uncomfortable (if not painful) hour daily, beginning with tonight. It can be called "heaven during a pandemic!"
NYJack
Posts: 8
Joined: 12 Dec 2020, 20:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

01 Feb 2021, 21:41

Guru, I placed the script with others in a file and for some reason F1, F2 and F3 do not trigger any actions. Also, confirming, F3 would leave the text same font and size of the text above the imported text? Also, where can I insert {ENTER} twice so I get two blank lines after the text is imported?

And HiSoKa, where can I insert {ENTER} twice so I get two blank lines after the text is imported?
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Copying highlighted text in Acrobat to different window in MS Word...

02 Feb 2021, 01:49

sorry i have no idea about hot code working with two monitor .
and about you want to triggered code when u release left click i think this will cause too much Trouble ,

so for new line using com use this:

Code: Select all

f1::WordPasteAtSelection()

WordPasteAtSelection()
{
    ClipSaved := ClipboardAll
    Clipboard := ""
    Send, ^c
    ClipWait, 1, 1
    oWord := ComObjActive("Word.Application")
	oWord.Selection.PasteAndFormat(16)			; replace this line with FanaticGuru code if u want change text format as he Described
    oWord.Selection.TypeParagraph			; this for new line if u want two linefeed u can Repeat it
    Clipboard := ClipSaved
}
return
for more details about com and how use it take a look here:

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=77

by the way u can also use ControlSend to send clipboard contents to inactive window , example Below:

Code: Select all

f1::WordPasteAtSelection()

WordPasteAtSelection()
{
    ClipSaved := ClipboardAll
    Clipboard := ""
    Send, ^c
    ClipWait, 1, 1
    ControlSend , _WwG1, %clipboard% "`n", Document1 - Word			; "`n" meaning enter or new line
    Clipboard := ClipSaved
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 349 guests