Copy highlighted text and search Google Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ebsalo
Posts: 1
Joined: 12 Oct 2021, 09:22

Copy highlighted text and search Google

Post by ebsalo » 12 Oct 2021, 09:35

I tried to create a shortcut that could copy any given highlighted text and search for it on Google. It occasionally works, but often it searches for the previous item that was on the Clipboard, as if it doesn't register the copy portion (although sometimes it does copy the highlighted text, but it searches for the previous text that I used this script on). Just some inconsistencies. I'm a thoroughgoing novice, so any help would be appreciated. Thanks in advance!

Here's my code:

Code: Select all

^!+x::
    KeyWait, Ctrl
    KeyWait, u
    Send, {Ctrl Down}c{Ctrl Up}
    ClipWait, 1
    if (ErrorLevel)
        return
    IfWinExist, ahk_class MozillaWindowClass
    {     Run, % "http://www.google.com/search?hl=en&q=" Clipboard
    } Else
    Run, % "http://www.google.com/search?hl=en&q=" Clipboard
Return

I'm having a similar issue with the code I use to search Merriam Webster:

Code: Select all

^!+m::
    KeyWait, Ctrl
    KeyWait, u
    Send, {Ctrl Down}c{Ctrl Up}
    ClipWait, 1
    if (ErrorLevel)
        return
    IfWinExist, ahk_class MozillaWindowClass
    {   Run, % "https://www.merriam-webster.com/dictionary/" . CLIPBOARD . ""
    } Else
    Run, % "https://www.merriam-webster.com/dictionary/" . CLIPBOARD . ""
Return
[Mod edit: [code][/code] tags added.]

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Copy highlighted text and search Google  Topic is solved

Post by safetycar » 16 Oct 2021, 06:02

Empty the clipboard so that ClipWait doesn't act based on what was there before... Clipboard := "" before the copy instruction.

erbanku
Posts: 7
Joined: 07 Oct 2021, 23:04

Re: Copy highlighted text and search Google

Post by erbanku » 16 Oct 2021, 09:19

I suggest you copy the text and then click a short key to search with Google.
Below is mine, After copy the text clicks Alt+Space to conduct a search. Simple and handy.

Code: Select all

!space:: Run https://www.google.com/search?q=%clipboard%

Post Reply

Return to “Ask for Help (v1)”