AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Post by MedBooster »

Thought I'd let you guys know of this script here; which basically through a keyboard shortcut (that you can change, but in this case it is Win+W and Win+Shift+W) basically copies what you have selected to your clipboard and searches for it on Google or DDG.

You could modify it to your liking by making it go to some dictionary/encyclopedia page instead.

To be honest I've thought about a script that does the opposite, basically takes what you have selected, copies it to your clipboard and searches for it for you in the PDF xchange advanced search section – So I would appreciate it if anyone could help with that (e.g. you select something in your browser, and it searches for that in pdf xce – based on what you've set the search to, a particular window , or all tabs. Would be nice to not have to copy paste it over manually all the time and click search)

I'm also using internet search by, but when you use that what you search does not get copied to your clipboard :)
image.png

Code: Select all

;Some improvements with the help of andreas@ESA:~$ sudo -i
#w::searchOrVisitFromClip("https://www.google.com/search?q=")
#+w::searchOrVisitFromClip("https://duckduckgo.com/?q=")

searchOrVisitFromClip(searchUrl){
    clip := clipboardAll
    clip := ""
    send, ^c
    ClipWait, 0.5
    if(ErrorLevel){
    } else if (clipboard ~= "^https?:\/\/") {   ; if clipboard content is an http or https protocol url
        run, % clipboard
    } else { ;search using the provided url
        run, % searchUrl clipboard
    }
    clipboard := clip ;put the last copied thing back in the clipboard
}

about the idea of a script that searches what you've selected (or the latest thing you've copied) in PDF xce even though it is not the active window – all it would need to do would be to copy the selected text → switch to pdf xce as the active window. → use the active advanced search shortcut→ , paste it in , → search (enter). Seems possible.
Last edited by MedBooster on Sat Jun 17, 2023 9:30 am, edited 1 time in total.
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: AutoHotKey script for searching the internet for selected phrase

Post by Tracker Supp-Stefan »

Hello MedBooster,

Many thanks for sharing the above!
I hope it is useful for other AHK users out there :)

The same can be achieved with tools of our own editor, but you will need to copy your selection first (Ctrl+C), and then do your internet search (with whatever other shortcut you have assigned to it - I tested with Ctrl + Alt + Shift + F ;) )

Kind regards,
Stefan
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script for searching the internet for selected phrase

Post by MedBooster »

Here's one that copies and searches for a selected phrase selected outside PDF xce (in a browser, Anki, Notion, whatever...) and searches for it in pdf-xce, making pdf xce the active window as well

#F is windows key+ F, but you can change it to whatever you'd like

for some reason it uses the ctrl+shift+F (for advanced search) instead of simple search Ctrl+F (^F) like I put in.
Still useful nevertheless.
remove SoundBeep if you find the beeping sound annoying

Code: Select all

;reference https://www.autohotkey.com/boards/viewtopic.php?t=90864



#IfWinExist ahk_exe PDFXEdit.exe
#F::
Clipboard := ""
Send ^c
ClipWait, 0
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
 Return
} Else WinActivate
SetKeyDelay, 25
Send ^F
Send ^v{Enter}
SoundBeep, 1500
Return
#IfWinExist
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script for searching the internet for selected phrase

Post by MedBooster »

and here's a modified one that searches for the last thing you copied if you currently don't have any highlighted/selected text
also changed the shortcut to win+shift+F because Win+F annoyingly sometimes opens some Office window

Code: Select all


#IfWinExist ahk_exe PDFXEdit.exe
#+F::
clip := clipboardAll
    clip := ""
    send, ^c
    ClipWait, 0.5
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
 Return
} Else WinActivate
SetKeyDelay, 25
Send ^F
SetKeyDelay, 25
Send ^v{Enter}
SoundBeep, 1500
Return
#IfWinExist

Last edited by MedBooster on Mon Jan 16, 2023 4:39 pm, edited 1 time in total.
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: AutoHotKey script for searching the internet for selected phrase

Post by Tracker Supp-Stefan »

Hello MedBooster,

Once again - many thanks for sharing those!
I am sure many others would find these useful!

Kind regards,
Stefan
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script for searching the internet for selected phrase

Post by MedBooster »

Those of you with multiple displays that you might rotate may also be interested in this script I just fixed today.
Currently it rotates the display your cursor is in, but you can change it to the display the active Window for example if you'd like to (everything you need is in there)

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.

;help received by [+] https://www.autohotkey.com/boards/viewtopic.php?f=76&t=87453&p=492976&sid=643f7444d745cc540978272aece7091f#p492976


#singleInstance force
#noEnv


;put together by MedBooster thank you to everyone that helped!

;the rotation code by masonjar13 ChangeDisplaySettingsExW down below edited in get active monitor down below 




lookup:={"^!down":[0,0],"^!right":[1,1],"^!up":[2,0],"^!left":[3,1]}
return

^!down::
^!right::
^!up::
^!left::

display := GetMonitorName("Point")


if (lookup[a_thisHotkey][2]){ ; rotating to portrait
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] < sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
} else { ; rotating to landscape
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] > sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
 }
screenRes_Set(cRes,display,lookup[a_thisHotkey][1])
return

screenRes_Set(WxHaF, Disp:=0, orient:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13
	Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
	Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",NumPut(F[3],NumPut(F[2],NumPut(F[1]
	,NumPut(32,NumPut(0x5C0080,NumPut(220,NumPut(orient,DM,84,"UInt")-20,"UShort")+2,"UInt")+92,"UInt"),"UInt")
	,"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)  
}
screenRes_Get(Disp:=0) {              ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
	Local DM, N:=VarSetCapacity(DM,220,0) 
	Return DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",-1, "Ptr",&DM)=0 ? ""
		: Format("{:}x{:}@{:}", NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt")) 
}



;Usage instructions below start of Vieira GetMonitorName

;GetMonitorName("Point") -> Uses the mouse location
;GetMonitorName("Point", [1921, 1]) -> Uses the provided coordinates
;GetMonitorName("Window") -> Uses the active window
;GetMonitorName("Rect", [1921, 1, 1951, 10]) -> Uses the provided rectangle coordinates


;Get monitor cursor by Vieira

GetMonitorName(method := "Window", coords := "", default_to := "Nearest") {
    static default := {"Null": MONITOR_DEFAULTTONULL := 0x0, "Primary": MONITOR_DEFAULTTOPRIMARY := 0x1, "Nearest": MONITOR_DEFAULTTONEAREST := 0x2}
    If (method = "Window")
        hMonitor := DllCall("MonitorFromWindow", "UInt", WinExist("A"), "UInt", default[default_to], "Ptr")
    Else if (method = "Point") {
        if coords
            x := coords[1], y := coords[2]
        Else
            MouseGetPos, x, y
        hMonitor := DllCall("MonitorFromPoint", "Int64", (x&0xFFFFFFFF) | (y<<32), "Int", default[default_to], "Ptr")
    }
    Else if (method = "Rect") {
        if !coords
            Throw % "Rect method requires coordinates"
        VarSetCapacity(RECT, 16, 0)
        NumPut(coords[4], NumPut(coords[3], NumPut(coords[2], NumPut(coords[1], &RECT, "UInt"), "UInt"), "UInt"), "UInt")
        hMonitor := DllCall("MonitorFromRect", "Ptr", &RECT, "UInt", default[default_to], "Ptr")
    }
    Else
        Throw % "Invalid method"
    NumPut(VarSetCapacity(MONITORINFOEX, 40 + (32 << !!A_IsUnicode)), MONITORINFOEX, 0, "UInt")
    DllCall("GetMonitorInfoW", "Ptr", hMonitor, "Ptr", &MONITORINFOEX)
    return StrGet(&MONITORINFOEX + 40, 32)
}
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6829
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

AutoHotKey script for searching the internet for selected phrase

Post by Paul - Tracker Supp »

:)
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Post by MedBooster »

I fixed it a bit so that it does not paste the text into the document itself rather than inserting it into the advanced search bar.
if you want to use simple search, just change
^+F
(ctrl+shift+F) to whatever you have set the simple search tool to Usually it is
^F
(ctrl+F)


Code: Select all

;reference https://www.autohotkey.com/boards/viewtopic.php?t=90864
;https://forum.pdf-xchange.com/viewtopic.php?p=165469#p165469
;sleep delays are added to stop the phrase from being copied into the document rather than the search bar 

#IfWinExist ahk_exe PDFXEdit.exe
#+F::
clip := clipboardAll
    clip := ""
    send, ^c
    ClipWait, 0.5
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
 Return
} Else WinActivate
Sleep 100
Send ^+F
Sleep 100
Send ^v
Sleep 50
Send {Enter}
SoundBeep, 200
Return
#IfWinExist



Note: for it to work properly you have to not have any text selected in the active PDF in PDF-xce. If you do have any text selected in the active PDF, it will be copied over to the advanced search bar along with the text you are copying over from another program (for me it is usually my browser (Firefox), Anki or Notion.
So that's the programs I am using the AutoHotKey script with.
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17818
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Post by Tracker Supp-Stefan »

Hello MedBooster,

Many thanks for sharing the updated version as well!

Kind regards,
Stefan
MedBooster
User
Posts: 1011
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Post by MedBooster »

Actually... although this one is more stable... it turns out the issue of it pasting in the result was not delays, but actually that if anything else in the advanced search panel than the search bar itself is selected – you can not use the Ctrl+Shift+F shortcut to highlight it :)

viewtopic.php?t=40398

So I hope that is a quick fix

Only then the AHK script should work well, so I hope that is a quick fix :))
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6829
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: AutoHotKey script for searching the selected text in PDF-xchange , and another for program→browser

Post by Paul - Tracker Supp »

Hi, MedBooster

I reported both these to the devs. I hope to hear something soon, I think they are otherwise engaged right now. As I see it much depends on their response to the CTRL+Shift+f report.

Kind regards,
Paul - Tracker Supp
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Post Reply