Hey there AHK Community, It's been a while hasn't it?
I've recently been designing scripts for my new mouse, which features a total of 13 programmable buttons and my new keyboard, which features 12 programmable buttons.
Getting all the codes was a B*****, but now that I have em, the work has begun.
Here is a script I've been working on, it is an upgrade to the googler script written by jimdavis.
It features:
[*:10zprsb2] Multiple Search Engines
[*:10zprsb2] Better Browser Checking
[*:10zprsb2] A Nice Menu
[*:10zprsb2] Awesome Sauce
Some notes on it:
[*:10zprsb2] The subroutines are a bit of a hack... I should probably find a better way to do this. In fact, I'll do that next. Suggestions?
[*:10zprsb2] It is dominantly English. I'll be including multi-language support soon.
[*:10zprsb2] It does have a limit to how big queries can be... don't try searching the entire works of Shakespeare....
[*:10zprsb2] Hmm.. I should probably add a section to clear the variables and de-initialize the script to save memory...
Anyway, here it is:
#NoEnv
#SingleInstance force
CoordMode, Menu
;############# Preamble #####################
SendMode Input
;############## Menu ######################
Menu, searchMenu, Add, &Google, gCall
Menu, searchMenu, Add, &Wikipedia, wCall
Menu, searchMenu, Add, Wolfram &Alpha, wACall
Menu, searchMenu, Add, Google &Images, gICall
Menu, searchMenu, Add, Google &News, gNCall
Menu, searchMenu, Add, &Pipl, pCall
Menu, searchMenu, Default, &Google
XButton2:: Menu, searchMenu, Show
return
;############### Functions ###################
searchWith(engine)
{
browser:="""" . DefaultBrowser() . """"
BlockInput, on
prevClipboard = %clipboard%
clipboard=
Send, ^{Insert}
BlockInput, off
ClipWait, 2
if ErrorLevel = 0
{
searchQuery := formatString(clipboard)
IfInString, searchQuery, .
{
IfInString, searchQuery, +
%engine%Search(searchQuery)
else
urlQuery(searchQuery)
}
else
{
%engine%Search(searchQuery)
}
else
{
MsgBox, The clipboard is empty. Please highlight a string before searching!
}
return
}
clipboard = %prevClipboard%
return
}
formatString(searchQuery)
{
StringReplace, searchQuery, searchQuery, `r`n, %A_Space%, All
Loop
{
noExtraSpaces=1
StringLeft, leftMost, searchQuery, 1
IfInString, leftMost, %A_Space%
{
StringTrimLeft, searchQuery, searchQuery, 1
noExtraSpaces=0
}
StringRight, rightMost, searchQuery, 1
IfInString, rightMost, %A_Space%
{
StringTrimRight, searchQuery, searchQuery, 1
noExtraSpaces=0
}
If (noExtraSpaces=1)
break
}
StringReplace, searchQuery, searchQuery, \, `%5C, All
StringReplace, searchQuery, searchQuery, %A_Space%, +, All
StringReplace, searchQuery, searchQuery, `%, `%25, All
return searchQuery
}
urlQuery(query)
{
Run, %browser% %query%
}
DefaultBrowser()
{
;-- Find .htm document type
RegRead l_DocumentType,HKEY_CLASSES_ROOT,.htm\
if ErrorLevel
{
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% -
Error reading the following registry key: HKEY_CLASSES_ROOT\.htm\
)
return
}
;-- Get default shell command for document type
RegRead l_DefaultShellCommand,HKEY_CLASSES_ROOT,%l_DocumentType%\shell\
;-- If not found or blank, set to "open"
if ErrorLevel
l_DefaultShellCommand:="open"
else
if l_DefaultShellCommand is Space
l_DefaultShellCommand:="open"
;-- Get command line for default web browser
RegRead
,l_BrowserCommand
,HKEY_CLASSES_ROOT
,%l_DocumentType%\shell\%l_DefaultShellCommand%\command
if ErrorLevel
{
outputdebug,
(ltrim join
Function: %A_ThisFunc% -%A_Space%
Error reading the following registry key:%A_Space%
HKEY_CLASSES_ROOT\
%l_DocumentType%\
shell\
%l_DefaultShellCommand%\
command
)
return
}
;-- If necessary, remove first set of double-quotes from 1st parameter
if SubStr(l_BrowserCommand,1,1)=""""
Loop 2
StringReplace l_BrowserCommand,l_BrowserCommand,"
;-- SplitPath
SplitPath l_BrowserCommand,l_BrowserProgram,l_BrowserPath
;-- If necessary, remove extra junk from l_BrowserProgram
if l_ExtPos:=InStr(l_BrowserProgram,".exe ")
l_BrowserProgram:=SubStr(l_BrowserProgram,1,l_ExtPos+3)
;-- Return full path of browser program
Return l_BrowserPath . "\" . l_BrowserProgram
}
;############ Search Engines #############
; Google
gCall:
searchWith("Google")
return
GoogleSearch(query)
{
Run, %browser% https://www.google.com/search?hl=en&q=%query%
}
; WikiPedia
wCall:
searchWith("Wikipedia")
return
WikipediaSearch(query)
{
Run, %browser% http://en.wikipedia.org/w/index.php?search=%query%
}
; Wolfram Alpha
wACall:
searchWith("WolframAlpha")
return
WolframAlphaSearch(query)
{
Run, %browser% https://www.wolframalpha.com/input/?i=%query%
}
; Google Images
gICall:
searchWith("GoogleImages")
return
GoogleImagesSearch(query)
{
Run, %browser% https://www.google.com/search?hl=en&tbm=isch&q=%query%
}
; Google News
gNCall:
searchWith("GoogleNews")
return
GoogleNewsSearch(query)
{
Run, %browser% https://www.google.com/search?hl=en&tbm=nws&q=%query%
}
; Pipl
pCall:
searchWith("Pipl")
return
PiplSearch(query)
{
Run, %browser% https://pipl.com/search/?q=%query%
}
; Template for new engine
;
;{Subroutunename}:
; searchWith("{Search Engine Name}")
;return
;
;{Search Engine Name}Search(query)
;{
; Run, %browser% {Search Engine Search String}%query%
;}
;
Any comments? Suggestions? Waffles?
Thank you,
--NictraSavios




