copy in Adobe Reader - no clipboard owner Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

copy in Adobe Reader - no clipboard owner

23 Feb 2019, 03:32

Using Adobe Reader seems to be an old problem but wondering if anyone has a way around this.

To replicate it I have a short script below, the DLL returns 0

Open a file in adobe reader

I included comments in the code

Code: Select all

f:: ; after you highlighted some text in adobe click f
send, ^c
msgbox, % clipboard ; will be empty
return

q:: ; after you copied text in adobe click q
msgbox, % DllCall("GetClipboardOwner", Ptr) ; will be 0
return
Last edited by AHKStudent on 23 Feb 2019, 11:27, edited 1 time in total.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 04:03

Try this:

Code: Select all

f:: ; works for me
	While (Clipboard != "" && A_Index <= 90) {  ; This While loop is for normal use redundant, but under heavy load useful.
		Clipboard := ""
		Sleep, 10
	}
	While (Clipboard = "" && A_Index <= 6) {
		Send, ^c
		Sleep, 150
	if !Clipboard
		msgBox Mark some text first!	; will be empty
 	else	msgbox, % clipboard		; will be loaded
 return
 
Edit: Better finish!
Edit2: Fixing typo!
Last edited by rommmcek on 23 Feb 2019, 05:34, edited 1 time in total.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 05:25

rommmcek wrote:
23 Feb 2019, 04:03
Try this:

Code: Select all

f:: ; works for me
	While (Clipboard != "" && A_Index <= 90) {  ; This While loop is for normal use redundant, but under heavy load useful.
		Clipboard := ""
		Sleep, 10
	}
	While (Clipboard = "" && A_Index <= 6) {
		Send, ^c
		Sleep, 150
	if !ClipBord
		msgBox Mark some text first!	; will be empty
 	else	msgbox, % clipboard		; will be loaded
 return
Edit: Better finish!
This worked for me (I call the clipboard on first msgbox), only thing left to solve is how to get results from the DLL that is not a 0

Code: Select all

f:: ; works for me
	While (Clipboard != "" && A_Index <= 90) {  ; This While loop is for normal use redundant, but under heavy load useful.
		Clipboard := ""
		Sleep, 10
	}
	While (Clipboard = "" && A_Index <= 6) {
		Send, ^c
		Sleep, 150
	if !ClipBord
		msgBox, % clipboard ; Mark some text first!	; will be empty ; works for me
 	else	msgbox, % clipboard		; will be loaded
	}
 return
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 05:33

Sorry, there was typo! if !ClipBord should be if !Clipboard!!!!!
With DllCall unfortunately I do not have experience!
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 05:34

rommmcek wrote:
23 Feb 2019, 05:33
Sorry, there was typo! if !ClipBord should be if !Clipboard!!!!!
With DllCall unfortunately I do not have experience!
thanks, it works
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 05:46

Looks like handle is retrieved only when Clipboard is occupied.

Code: Select all

	SetBatchLines, -1
	VarSetCapacity(vOutput, 55*1000000*2)
	Loop, 200000
		vOutput .= "abcdefghijklmnopqrstuvwxyz`tabcdefghijklmnopqrstuvwxyz`r`n" ; big data by Jeeswg to occupy Clipboard as long as possible
	Clipboard := vOutput
	MsgBox % DllCall("GetClipboardOwner", Ptr)
Edit: Works even for small data e.g. Clipboard := "String"!
Edit2: Fixing copy paste error!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Cannot copy in Adobe - clipboard empty  Topic is solved

23 Feb 2019, 09:59

- You should probably rename the thread to something like:
copy in Adobe Reader - no clipboard owner
- It would be helpful to know why it is you want to know what program set the clipboard contents.

INTRO
- If you press Ctrl+C in a program, and then use GetClipboardOwner, you should get an hWnd for the program that set the clipboard contents.
- This worked in multiple programs, e.g. Notepad and Internet Explorer, but not Adobe Reader (it returned 0).
- I did a search for 'getclipboardowner adobe', and it appears that a 'randy_dom' asked on multiple forums about this, although they received little useful feedback, e.g.:
winapi - GetClipBoardOwner with Adobe acrobat reader - Stack Overflow
https://stackoverflow.com/questions/10397320/getclipboardowner-with-adobe-acrobat-reader

TESTS

Code: Select all

q:: ;test get clipboard owner
;MsgBox, % A_LastError
hWnd := DllCall("user32\GetClipboardOwner", Ptr)
;hWnd := DllCall("user32\GetOpenClipboardWindow", Ptr)
WinGetClass, vWinClass, % "ahk_id " hWnd
WinGet, vPName, ProcessName, % "ahk_id " hWnd
MsgBox, % hWnd "`r`n" vWinClass "`r`n" vPName
return

A POSSIBLE WORKAROUND FOR ADOBE READER
- I used NirSoft InsideClipboard to look for any info on the clipboard identifying Adobe Reader (as having set the clipboard contents).
- The RTF text stored on the clipboard contained this: '{\*\generator Adobe Acrobat Reader '. Cheers.

Code: Select all

w:: ;check if RTF text on clipboard contains 'Adobe Acrobat Reader'
vRtf := JEE_ClipboardGetRtf()
MsgBox, % !!InStr(vRtf, "{\*\generator Adobe Acrobat Reader ")
return

JEE_ClipboardGetRtf(vEnc:="CP0")
{
	local
	vFormat := DllCall("user32\RegisterClipboardFormat", Str,"Rich Text Format", UInt)
	return JEE_ClipboardGetText(vFormat, vEnc)
}

JEE_ClipboardGetText(vFormat:=0xD, vEnc:="")
{
	local
	;CF_LOCALE := 0x10 ;CF_UNICODETEXT := 0xD
	;CF_OEMTEXT := 0x7 ;CF_TEXT := 0x1
	if !DllCall("user32\IsClipboardFormatAvailable", UInt,vFormat)
	|| !DllCall("user32\OpenClipboard", Ptr,0)
		return
	if !hBuf := DllCall("user32\GetClipboardData", UInt,vFormat, Ptr)
	{
		DllCall("user32\CloseClipboard")
		return
	}

	pBuf := DllCall("kernel32\GlobalLock", Ptr,hBuf, Ptr)
	vSize := DllCall("kernel32\GlobalSize", Ptr,hBuf, UPtr)
	VarSetCapacity(vOutput, vSize, 0)
	DllCall("msvcrt\memcpy", Ptr,&vOutput, Ptr,pBuf, UPtr,vSize, "Cdecl Int")
	if !(vEnc = "")
		vOutput := StrGet(&vOutput, vSize, vEnc)
	VarSetCapacity(vOutput, -1)

	DllCall("kernel32\GlobalUnlock", Ptr,hBuf)
	DllCall("user32\CloseClipboard")
	return vOutput
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 11:14

@jeeswg: I was speaking of the guru, the guru is here! Very classy piece of code!
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Cannot copy in Adobe - clipboard empty

23 Feb 2019, 12:14

jeeswg wrote:
23 Feb 2019, 09:59
- You should probably rename the thread to something like:
copy in Adobe Reader - no clipboard owner
Thank you, I renamed the title

I tested it and it did not work for me at first, so I downloaded the tool you mentioned inside clipboard and for me it says "{\rtf1\ansi\ansicpg1252\uc1 {\fonttbl\f0\fswiss\fcharset177 Constantia;}\pard\plain\ql\f0\fs20 {\fs22 mention the}}"

None of the entries in inside clipboard had the words generator Adobe Acrobat Reader etc

I am using Adobe Acrobat Reader DC 19 and I tried with a few different pdf files

I changed your program to MsgBox, % !!InStr(vRtf, "ansicpg1252")

And for me its working and it does its not on the machine. A lot of people tried to solve this over the years for others, this is as close as it has gotten :thumbup: :thumbup:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: copy in Adobe Reader - no clipboard owner

23 Feb 2019, 14:51

- The string 'ansicpg1252' could feasibly be put there by other programs. Is there not any other 'Adobe' or 'DC' etc string?
- A key question is what you're hoping to achieve, and therefore how much effort to put in to trying to solve the problem, and/or other possible workarounds.
- The code below tries to detect whenever Adobe Reader uses the clipboard. You can replace 'SoundBeep' with some alternative action.

Code: Select all

#IfWinActive, ahk_class AcrobatSDIWindow

;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

~^c::
;~^x::
SoundBeep
return

~*LButton::
oAcc := Acc_ObjectFromPoint(vChildID)
vName := oAcc.accName(vChildID)
vValue := oAcc.accValue(vChildID)
oAcc := ""
if (vName = "Copy Ctrl+C")
	;MsgBox, % "[" vName "]"
	SoundBeep
return

~c::
DetectHiddenWindows, Off
if !(hWnd := WinExist("ahk_class #32768"))
	return
WinGet, vPName, ProcessName, % "ahk_id " hWnd
if !(vPName = "AcroRd32.exe")
	return
SendMessage, 0x1E1, 0, 0,, % "ahk_id " hWnd ;MN_GETHMENU := 0x1E1
hMenu := ErrorLevel
vID := DllCall("user32\GetMenuItemID", Ptr,hMenu, Int,4, UInt)
if (vID = 6038) ;Copy
	SoundBeep
return

#IfWinActive
- Actually, a far simpler script is this one, which may be useful:

Code: Select all

#Persistent
OnClipboardChange("OnClipboardChangeFunc") ;put this at the top of the script (in the auto-execute section)

OnClipboardChangeFunc()
{
	SoundBeep
}
- Btw for eager readers, the original thread title was 'Cannot copy in Adobe - clipboard empty'.
- Thanks rommmcek.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 328 guests