键盘快捷键用于搜索选定/突出显示的文本

键盘快捷键用于搜索选定/突出显示的文本

在 Chrome 中,您可以突出显示网页上的某些文本,然后使用右键单击上下文菜单在新选项卡中打开所选文本的 Google 搜索。

如果我可以使用键盘快捷键而不是右键单击菜单来访问此功能,那将非常方便。我尝试搜索现有扩展,并在此处搜索现有键盘快捷键列表:https://support.google.com/chrome/answer/157179?hl=en

有人知道如何实现这个吗?

答案1

在 Chrome 中此命令有效:

  • 首先突出显示一些文本
  • 点击CTRL+ C- 复制文本
  • 点击CTRL+ T- 这将创建一个新选项卡并使其成为焦点
  • 点击CTRL+ V- 这会将文本粘贴到多功能框中(Chrome 默认将光标放在那里)
  • 点击Enter- 这将搜索多功能框中的文本

想要自动化吗?使用自动热键使用++CTRL使其成为自动宏使用 此脚本::AltS

^!s::
  Send ^c
  Send ^t
  Send ^v
  Send {Enter}
Return

仅供参考,我测试了该脚本并且它在 Chrome 中运行。

答案2

我在 AHK 中对此也有两个答案。

这在任何地方都适用(不仅限于 Chrome)。只需选择文本并按Windows+G

#g::  ;;Google selected text
   Send, ^c
   Run, http://www.google.com/search?q=%Clipboard%
Return

其中一个是我的在这里回答。选择文本并按Windows+ Shift+ G。这不同之处在于它只会为您提供剪贴板上的链接。

; Search google for the highlighted word
; then get the first link address and put it on the Clipboard

^!r:: Reload

#+g::
    bak = %clipboard%
    Send, ^c
    ;clipboard = %bak%`r`n%clipboard%
    Query = %clipboard%
    wb := ComObjCreate("InternetExplorer.Application")
    ;wb := IEGet()
    wb.Visible := false
    wb.Navigate("www.google.com/search?q=" Query)
    While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
      sleep 100
    ; loop % (Nodes := wb.document.getElementById("rso").childNodes).length
    ;     Links_urls .= (A_index = 1) ? Nodes[A_index-1].getElementsByTagName("a")[0].href : "`n" . Nodes[A_index-1].getElementsByTagName("a")[0].href
    ; Msgbox %Links_urls%

    Nodes := wb.document.getElementById("rso").childNodes
    First_link := Nodes[0].getElementsByTagName("a")[0].href
    Clipboard = %First_link%
    TrayTip, First Link on Google Search, %First_link% `r`n Ctrl+V to paste the link
return

答案3

根据 Parivar Saraff 的建议这里,这里有一个 3 合 1 的 AutoHotKey 脚本:

;Hotkey Modifier Symbols (for how to customize the hotkeys) https://www.autohotkey.com/docs/Hotkeys.htm#Symbols

#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.

;                               Google-search selected text
;  Usage:ctrl+shift+G
^+g::  
{
   Send, ^c
   Sleep 150
   Run, http://www.google.com/search?q=%Clipboard% ;(изм.себе на google.com.ua)
Return

}

;                               Google-dictionary selected text
;  Usage:ctrl+shift+D
^+d::
{
   Send, ^c
   Sleep 150
   Run, https://www.google.com/search?q=define:%Clipboard% ;(изм.себе на google.com.ua)
Return

}

;                           Wikipedia-search selected text by using google "site:" operator
;  Usage:ctrl+shift+W
^+w:: 
{
   Send, ^c
   Sleep 150
   Run, https://www.google.com/search?q=site:wikipedia.org %Clipboard% ;(изм.себе на google.com.ua)
Return

}

还突出显示了文本转换脚本(网络上此类脚本变体的组合):

;Hotkey Modifier Symbols (for how to customize the hotkeys) https://www.autohotkey.com/docs/Hotkeys.htm#Symbols


    ;Hotkey Modifier Symbols (for how to customize the hotkeys) https://www.autohotkey.com/docs/Hotkeys.htm#Symbols


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.



cycleNumber := 1

#IfWinNotActive ahk_class XLMAIN

                                ;Highlighting any text, and then pressing that HotKey will cycle through the 4 most common text casings, converting the highlighted text right in-line.

                                    ;For example:

    ;If you highlight "This is a test sentence", and then hit that HotKey once, it'll make it all UPPERCASE ("THIS IS A TEST SENTENCE").
    ;Hit the HotKey again, it'll convert it to lowercase ("this is a test sentence").
    ;Hit it again and it'll convert it to Sentence case ("This is a test sentence"). (First letter is capitalized, rest is lower-case).
    ;Finally, hit it one more time and it'll convert it to Mixed case, or what I often call, "camel-case" ("This Is A Test Sentence"). (Each word is capitalized).

;  Usage:Ctrl+Shift+C
^+c:: 

If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else If (cycleNumber==3)
{
ConvertSentence()
cycleNumber:= 4
}
Else
{
ConvertMixed()
cycleNumber:= 1
}
Return

ConvertUpper()
{
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ; Copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for SendInput sending Windows linebreaks 
    StringUpper, Clipboard, Clipboard
    Len:= Strlen(Clipboard) ;Set number of characters ;Set number of characters
    SendInput, ^v ; Pastes new text
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(clipSave, 0) ; Free memory
    Clipboard := clipSave ;Restore previous clipboard
}

ConvertLower()
{
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ; Copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for SendInput sending Windows linebreaks
    StringLower, Clipboard, Clipboard
    Len:= Strlen(Clipboard) ;Set number of characters
    SendInput, ^v ; Pastes new text
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(clipSave, 0) ; Free memory
    Clipboard := clipSave ;Restore previous clipboard
}

ConvertSentence()
{
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ; Copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for SendInput sending Windows linebreaks
    StringLower, Clipboard, Clipboard
    Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
    Len:= Strlen(Clipboard) ;Set number of characters
    SendInput, ^v ; Pastes new text
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(clipSave, 0) ; Free memory
    Clipboard := clipSave ;Restore previous clipboard
}

ConvertMixed()
{
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ; Copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for SendInput sending Windows linebreaks
    StringUpper Clipboard, Clipboard, T
    Len:= Strlen(Clipboard) ;Set number of characters
    SendInput, ^v ; Pastes new text
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(clipSave, 0) ; Free memory
    Clipboard := clipSave ;Restore previous clipboard
}

#IfWinNotActive

                        ; Convert selected text to inverted case
                                    ;    Ex: THIS_is-a_tESt -> this_IS-A_TesT
; Usage:ctrl+Shift+I 
^+i::
    Convert_Inv()
RETURN
Convert_Inv()
{
    ; save original contents of clipboard
    Clip_Save:= ClipboardAll

    ; empty clipboard
    Clipboard:= ""

    ; copy highlighted text to clipboard
    Send ^c{delete}

    ; clear variable that will hold output string
    Inv_Char_Out:= ""

    ; loop for each character in the clipboard
    Loop % Strlen(Clipboard)
    {
        ; isolate the character
        Inv_Char:= Substr(Clipboard, A_Index, 1)

        ; if upper case
        if Inv_Char is upper
        {
            ; convert to lower case
           Inv_Char_Out:= Inv_Char_Out Chr(Asc(Inv_Char) + 32)
        }
        ; if lower case
        else if Inv_Char is lower
        {
            ; convert to upper case
           Inv_Char_Out:= Inv_Char_Out Chr(Asc(Inv_Char) - 32)
        }
        else
        {
            ; copy character to output var unchanged
           Inv_Char_Out:= Inv_Char_Out Inv_Char
        }
    }
    ; send desired text
    Send %Inv_Char_Out%
    Len:= Strlen(Inv_Char_Out)

    ; highlight desired text
    Send +{left %Len%}

    ; restore original clipboard
    Clipboard:= Clip_Save
}
                            ; Text–only paste from ClipBoard (while the clipboard formatted text itself is being untouched)
; Usage:ctrl+Shift+I 
^+v::                          
   Clip0 = %ClipBoardAll%
   Clipboard = %Clipboard%  ; Convert clipboard text to plain text.
   StringReplace, clipboard, clipboard,%A_SPACE%",", All ; Remove space introduced by WORD
   StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for Send sending Windows linebreaks
   Send ^v                       ; For best compatibility: SendPlay
   Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %Clip0%           ; Restore original ClipBoard
   VarSetCapacity(Clip0, 0)      ; Free memory
Return

                                    ; Wrap selected text in double quotes->" "
; Usage:Ctrl+Shift+Q
^+q::
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ; Copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ; Fix for SendInput sending Windows linebreaks
    Clipboard := Chr(34) . Clipboard . Chr(34)
    Len:= Strlen(Clipboard) ;Set number of characters
    SendInput, ^v ; Pastes new text
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(clipSave, 0) ; Free memory
    Clipboard := clipSave ;Restore previous clipboard
Return

; RELOAD 
!+^x::
   SplashTextOn,,,Updated script,
   Sleep,200
   SplashTextOff
   Reload
   Send, ^s
Return

答案4

使用自动热键如上

^!s::
  Send ^c
  Sleep 100
  Send ^t
  Send ^v
  Send {Enter}
Return

注意:我添加了“Sleep 100”以避免之前的剪贴板搜索

相关内容