Adobe Acrobat DC, Shortcut to change highlight color

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JanSal
Posts: 21
Joined: 19 Aug 2016, 02:19

Adobe Acrobat DC, Shortcut to change highlight color

19 Apr 2018, 13:49

I am trying to create a shortcut in order to change the highlight color of marked text segment in Adobe Acrobat DC rapidly.
The script I am using is buggy and messes up the keyboard every once in a while... (it behaves as if the shift key were locked, preventing the user from doing anything then selecting text) :crazy:
I would appreciate the feedback of other Acrobat users that have managed to achieve similar things in one or another way (maybe via COM) and suggestions on how to improve the current script in general.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
;;;
; Change color
;;
global clr := {}						; Associative array to store the color's position under its name.
clr.Insert("green", {x:"3", y:"3"})		
clr.Insert("red", {x:"0", y:"2"})

openProp(){								; Opens property menu for highlighted, selected text
	SendInput, +{F10}					; Opens context menu 
	SendInput, {Up}{Enter}				; Access of 'Properties'
}

closeProp(boolSave := 1) {
	if (boolSave) {
		ControlClick, Button41			; OK button Property menu
	}
	else {
		ControlClick, Button42			; Cancel button Property menu
	}
}

pickColor(color := "") {
	WinWaitActive, ahk_class #32770
	WinActivate, ahk_class #32770
	SendInput, {Enter}					; Focus is by default set on color button.
	Sleep, 30
	SendInput, {Down}					; Acceses Color dropdown, loops pick color at certain position
	Loop % clr[color].x
	{
		SendInput, {Right}
	}
	Loop % clr[color].y
	{
		SendInput, {Down}
	}
	SendInput, {Enter}
}

$<^>!+g::
	BlockInput, On						; Prevent user from messing it up
	BlockInput, Mouse
	openProp()
	pickColor("green")
	closeProp()
	BlockInput, Default
	BlockInput, Off
return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Adobe Acrobat DC, Shortcut to change highlight color

19 Apr 2018, 16:34

There are 2 places in the script that use shift: the hotkey $<^>!+g:: and the function openProp().

Try changing the function to:

Code: Select all

openProp(){								; Opens property menu for highlighted, selected text
	SendInput, {Shift Down}{F10}{Shift Up}		; Opens context menu 
	SendInput, {Up}{Enter}				; Access of 'Properties'
}
If the above doesnt fix the intermittent shift problem you can put keywaits in the hotkey subroutine for each hotkey modifier key.

HTH
JanSal
Posts: 21
Joined: 19 Aug 2016, 02:19

Re: Adobe Acrobat DC, Shortcut to change highlight color

21 Apr 2018, 06:31

@ Xtra
I appreciate the time you took to reply to this post and thank you for your suggestions.
Waiting for the keys to get released seems to be the solution to the interference problem :shifty: I am going to apply and test this approach with other scripts that used to trouble mind and keyboard equally from time to time.
@ you, RegEx user
In order to enable the user to change the color of the selected tool (e.g. Highlight Tool) without making a text selection, I opted for another, faster way to access the property menu of the respective tool (Ctrl+e).
Since the color button location varies from tool to tool, I wanted to check the WinTitle with a regular expression. The SetTitleMatchMode documentation states:
RegEx [v1.0.45+]: Changes WinTitle, WinText, ExcludeTitle, and ExcludeText to accept regular expressions. Do not enclose such expressions in quotes when using them with commands. For example: WinActivate Untitled.*Notepad.
But the RegEx at line 16 triggers an error. Any idea how to get this working?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
;;;
; Change color
;;
global boolClosePropWin := 1
global clr := {}						; Associative array to store the color's position under its name.
clr.Insert("blue", {x:"5", y:"2"})
clr.Insert("green", {x:"3", y:"3"})
clr.Insert("orange", {x:"1", y:"1"})		
clr.Insert("red", {x:"0", y:"2"})
clr.Insert("yellow", {x:"1", y:"3"})

navToColorButton() {
	SetTitleMatchMode, RegEx
	if WinActive("^(High|Pencil|Sticky|Under|Arrow|Line).*\s\bProperties\b") {
		SendInput, {Up 2}
		SetTitleMatchMode, 2
	}
	else if WinActive("^(Rectangle|Oval|Text).*\s\bProperties\b") {
		SendInput, {Up 2}
		SendInput, {Right}
		SetTitleMatchMode, 2
	}	
	else {
		closeProp()
		SetTitleMatchMode, 2
		Exit
	}
}

openProp(){
	if !(WinExist("ahk_class AVL_AVFloating")) {
		SendInput, {Ctrl Down}e{Ctrl Up}	
		WinWait, ahk_class AVL_AVFloating
		WinActivate
	}
	else {
		boolClosePropWin := 0	
	}
}

closeProp() {
	if (WinExist("ahk_class AVL_AVFloating") && boolClosePropWin) {
		SendInput, {Ctrl Down}e{Ctrl Up}
	}
	boolClosePropWin := 1
}


pickColor(color := "") {
	KeyWait, RAlt
	KeyWait, Shift
	BlockInput, On						; Prevent user from messing it up
	BlockInput, Mouse
	openProp()
	navToColorButton()
	SendInput, {Down}
	SendInput, {Up 7}				
	Loop % clr[color].x
	{
		SendInput, {Right}
	}
	Loop % clr[color].y
	{
		SendInput, {Down}
	}
	SendInput, {Enter}
	closeProp()
	BlockInput, Default
	BlockInput, Off
}

#ifWinActive, ahk_exe Acrobat.exe
	<^>!+b::pickColor("blue")
	<^>!+g::pickColor("green")
	<^>!+o::pickColor("orange")
	<^>!+r::pickColor("red")
	<^>!+y::pickColor("yellow")
#ifWinActive
Last edited by JanSal on 21 Apr 2018, 07:36, edited 1 time in total.
JanSal
Posts: 21
Joined: 19 Aug 2016, 02:19

Re: Adobe Acrobat DC, Shortcut to change highlight color

21 Apr 2018, 07:35

Yes! Stupid me, I only read the first part of the paragraph in the documentation that advised against using quotes...
Thank you, swagfag!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Adobe Acrobat DC, Shortcut to change highlight color

21 Apr 2018, 08:28

Perhaps try:

Code: Select all

SendInput, {Shift Up}+{F10}
;or:
SendInput, {Shift Up}{Shift Down}{F10}{Shift Up}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
miguelscm
Posts: 1
Joined: 17 Dec 2022, 12:30

Re: Adobe Acrobat DC, Shortcut to change highlight color

17 Dec 2022, 13:16

Hi, is this still working? I'm looking for the same solution in the current version.
caja
Posts: 1
Joined: 03 Apr 2023, 13:27

Re: Adobe Acrobat DC, Shortcut to change highlight color

03 Apr 2023, 13:31

anyone have the right code for it?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NinjoOnline and 244 guests