Paste into InputBox

Get help with using AutoHotkey and its commands and hotkeys
arepas
Posts: 2
Joined: 29 Jun 2020, 14:04

Paste into InputBox

29 Jun 2020, 16:57

I'm trying to make a script that searches my highlighted text in Google and opens an InputBox (by pressing Ctrl+Caps lock) to slightly modify it. However, I cannot find a way to automatically paste the clipboard into the InputBox.
Here's what I have:

Code: Select all

    searchGoogle(query){
        StringReplace, query, query, %A_Tab%, , ALL ;delete all tabs from text in keyboard
        StringReplace, query, query, •, , ALL ;delete bullet points from text in keyboard
        search = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https www.google.com /search?q="%query%"  Broken Link for safety
        KeyWait Enter
        Run %search%
    }

^CapsLock::
    Clipboard =
    Send, ^c
    ClipWait
    queries := Clipboard
    StringReplace, queries, queries, %A_Tab%, , ALL ;delete all tabs from text in keyboard
    StringReplace, queries, queries, •, , ALL ;delete bullet points from text in keyboard

    InputBox, queries, Google Search, Edit Search term, , ,100, , , ,30,
    Send, ^v ;<<<***********THIS IS THE PART THAT DOES NOT WORK********
        if ErrorLevel
        ControlClick,Cancel ,Google Search
        else if (queries="")
        msgbox,Input is empty
        else   
        searchGoogle(queries)

    return

What am I doing wrong?? Any help would be appreciated. Thanks!
User avatar
Learning one
Posts: 154
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: Paste into InputBox

29 Jun 2020, 17:23

If you want to use InputBox, try this:

Code: Select all

SetTimer, SetInputBoxText, -100
InputBox, queries, Google Search, Edit Search term, , ,100, , , ,30,
return

SetInputBoxText:
WinWait, Google Search ahk_class #32770
ControlSetText, Edit1, %Clipboard%
return
You could also build simple GUI with Edit control and two Buttons, and than later set Edit text with GuiControl command
User avatar
boiler
Posts: 5556
Joined: 21 Dec 2014, 02:44

Re: Paste into InputBox

29 Jun 2020, 18:12

You can just use the Default parameter of InputBox to put the clipboard contents in it:

Code: Select all

Clipboard := "test string"
InputBox, queries, Google Search, Edit Search term,,,100,,,,30, % Clipboard
User avatar
Learning one
Posts: 154
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: Paste into InputBox

29 Jun 2020, 18:18

:facepalm: to myself
:thumbup: to boiler
arepas
Posts: 2
Joined: 29 Jun 2020, 14:04

Re: Paste into InputBox

30 Jun 2020, 05:42

Thank you both! That worked. I managed to add %queries% at the end of the InputBox, which prefills the text before executing the search. I still have to press the end button or right arrow if I want to edit it, but that's a minor usability issue.

Return to “Ask For Help”

Who is online

Users browsing this forum: 2ndprotocol, Bing [Bot], Chunjee, frosse, Google [Bot], malcev, navmesh, Zamfir and 52 guests