January 4, 2021

Custom Search Engines triggered by CapsLock modified hotkeys

With AutoHotkey it is pretty easy to add hotkeys to run a special search engine on the current text selection.
Moreover you can remap the else useless CapsLock key for this purpose.
I present here how it can be implemented and is implemented in the NWS PowerTool.

AutoHotkey implementation

In the AutoRun section of your AutoHotkey script add :

;================================================================================================
;  CapsLock processing.  Must double tap CapsLock to toggle CapsLock mode on or off.
; https://www.howtogeek.com/446418/how-to-use-caps-lock-as-a-modifier-key-on-windows/
;================================================================================================
; Must double tap CapsLock to toggle CapsLock mode on or off.
CapsLock:: ; <--- Must double tap CapsLock to toggle CapsLock mode on or off.
    KeyWait, CapsLock                                                   ; Wait forever until Capslock is released.
    KeyWait, CapsLock, D T0.2                                           ; ErrorLevel = 1 if CapsLock not down within 0.2 seconds.
    if ((ErrorLevel = 0) && (A_PriorKey = "CapsLock") )                 ; Is a double tap on CapsLock?
        {
        SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"  ; Toggle the state of CapsLock LED
        }
return

This will deactivate the CapsLock key. You need now to double tap CapsLock to activate or deactivate it.

See below for examples how to then implement CapsLock modified hotkeys to trigger search engines.

This makes use of the GetSelection function in ahk/Lib/GetSelection.ahk

NWS PowerTool Implementation

Some search engines are implemented in the NWS PowerTool by modifying the CapsLock key.

Code extract of ahk/NWS.ahk 

;================================================================================================
; Hotkeys with CapsLock modifier.  See https://autohotkey.com/docs/Hotkeys.htm#combo
;================================================================================================

#If (PowerTools_ConnectionsRootUrl != "")
CapsLock & c:: ;  <--- ConNext Global Search
sSelection:= GetSelection()
Run, https://connext.conti.de/search/web/search?query=%sSelection%     ; Launch with contents of clipboard
Return

#If

CapsLock & d:: ;  <--- Get DEFINITION of selected word.
sSelection:= GetSelection()
Run, http://www.google.com/search?q=define+%sSelection%     ; Launch with contents of clipboard
Return

CapsLock & b:: ;  <--- Bing search.
sSelection:= GetSelection()
If RegExMatch(sSelection,"(.*), (.*) <(.*)>",sMatch) ; From Outlook contact
    sSelection = %sMatch2% %sMatch1%#,Person ; Transform Firstname Lastname
Run, http://www.bing.com/search?q=%sSelection%     ; Launch with contents of clipboard
Return


CapsLock & g:: ; <--- GOOGLE the selected text.
sSelection:= GetSelection()
Run, http://www.google.com/search?q=%sSelection%             ; Launch with contents of clipboard
Return

;CapsLock & t:: ; <--- Do THESAURUS of selected text
;sSelection:= GetSelection()
;Run http://www.thesaurus.com/browse/%sSelection%             ; Launch with contents of clipboard
;Return


CapsLock & w:: ; <--- Do WIKIPEDIA of selected text
sSelection:= GetSelection()
Run, https://en.wikipedia.org/wiki/%sSelection%              ; Launch with contents of clipboard
Return

#If (Config = "Conti")
CapsLock & n:: ; <--- Open NWS Search or trigger NWS Search with selected text
PowerTools_NWSSearch()
return

#If

CapsLock & y:: ; <--- YouTube search of selected text
sSelection:= GetSelection()
Run, https://www.youtube.com/results?search_query=%sSelection%              ; Launch with contents of clipboard
return


References

NWS PowerTool Homepage

How-to-Geek: how to use capslock as a modifier key on Windows




No comments:

Post a Comment