Store string in variable between hotstring and end character? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Store string in variable between hotstring and end character?

27 Feb 2018, 09:50

Hello,

This following code is simple, I press ` then type downloads then press {space} and the downloads folder opens:

Code: Select all

::``downloads::
Run D:\Me\Downloads
return
However, let's say I want to make a hotstring that behaves like the following: I press ` then press g then {space} then type autohotkey forums. Can I catch such a hotstring and store whatever is after the {space} in a variable/string where I can use inside the script and make checks on?

What I intend to do at the end is catch the g after the ` and know that I want to google search something, then catch whatever is after the first space and open a google search of that.

Thanks in advance!
:morebeard:
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: Store string in variable between hotstring and end character?  Topic is solved

27 Feb 2018, 12:04

I have managed to create the script in a different way that I first thought was possible.

Here is the script if anyone is interested (hot to use is after script):

Code: Select all

;;;;;;;;;;;;;;;;;;;;
; Search Functions ;
;;;;;;;;;;;;;;;;;;;;

; Not my function, taken from somewhere else on the internet, can't credit author since I forgot where I got it from :(
uriEncode(str) {
    f = %A_FormatInteger%
    SetFormat, Integer, Hex
    If RegExMatch(str, "^\w+:/{0,2}", pr)
        StringTrimLeft, str, str, StrLen(pr)
    StringReplace, str, str, `%, `%25, All
    Loop
        If RegExMatch(str, "i)[^\w\.~%/:]", char)
           StringReplace, str, str, %char%, % "%" . SubStr(Asc(char),3), All
        Else Break
    SetFormat, Integer, %f%
    Return, pr . str
}

; Search Google
::``g::
Input, UserInput, T5 L25 C, {enter}.{esc}{tab}
textToInsert := uriEncode(UserInput)

googleUrl := "https://www.google.com/search?num=50&safe=off&site=&source=hp&q=REPLACEME&btnG=Search&oq=&gs_l="
safeUrl := StrReplace(googleUrl, "REPLACEME", textToInsert)

Run %safeUrl%
return

; Search Youtube
::``y::
Input, UserInput, T5 L25 C, {enter}.{esc}{tab}
textToInsert := uriEncode(UserInput)

youtubeUrl := "https://www.youtube.com/results?search_query=REPLACEME"
safeUrl := StrReplace(youtubeUrl, "REPLACEME", textToInsert)

Run %safeUrl%
return

; Search Autohotkey
::``a::
Input, UserInput, T5 L25 C, {enter}.{esc}{tab}
textToInsert := uriEncode(UserInput)

youtubeUrl := "https://www.google.com/search?num=50&safe=off&site=&source=hp&q=autohotkey%20REPLACEME&btnG=Search&oq=&gs_l="
safeUrl := StrReplace(youtubeUrl, "REPLACEME", textToInsert)

Run %safeUrl%
return
How to use:
If you want to search google for black banana, you type the following on your keyboard (had to pause my script so I can type this :D):

Code: Select all

`g{space}black{space}banana{enter}
It's that easy, and then a google search will open in your default browser. To search on youtube, you replace the g with a y and it just works. No GUI, the way I want it :D
:morebeard:
gregster
Posts: 9096
Joined: 30 Sep 2013, 06:48

Re: Store string in variable between hotstring and end character?

27 Feb 2018, 12:36

; Not my function, taken from somewhere else on the internet, can't credit author since I forgot where I got it from :(
Google works for that, too: ;)
https://autohotkey.com/board/topic/1736 ... /?p=121447
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: Store string in variable between hotstring and end character?

27 Feb 2018, 12:46

Thank you for pointing that out. Guess I was lazy? No other excuse comes to mind :D
:morebeard:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 114 guests