Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Noob question. How to respond to a hotstring with a command


  • Please log in to reply
16 replies to this topic
Marco Kotrotsos
  • Guests
  • Last active:
  • Joined: --
Hi, sorry if this has been answered elsewhere but i'm overwhelmed with options and new things to learn...its' great!.anyhoo...

what I would want is to have a hotstring respond to a command.

say if i type

wiki:AutoHotKey

it would open a browser and display the wiki page.

same goes for everything else like

goog:Heroes

and it would show the google searchresult for 'heroes'.

Thank you very very much...i think i will save an hour a day now! :)
Marco Kotrotsos

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Examples are given on the Hotstring page.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
what you want is a hotstring, though there are many better ways of doing this:

::goog:Heroes::
::wiki:Autohotkey::
::wiki:Python::
StringSplit, arg, A_ThisHotkey , :
lastarg := arg0
place := arg%lastarg%
lastarg--
type := arg%lastarg%
if (type="wiki")
  run, iexplore.exe http://en.wikipedia.org/wiki/%place% 
if (type="goog")
  run, iexplore.exe http://www.google.com/search?q=%place% 

Return

This of course doesn't cover the generic form, so try this instead

#s::
inputbox, command, Title, Type what you want to seach for and how`nE.G. wiki:Autohotkey
StringSplit, arg, command , :
place := arg2
type := arg1

if (type="wiki")
  run, iexplore.exe http://en.wikipedia.org/wiki/%place% 
if (type="goog")
  run, iexplore.exe http://www.google.com/search?q=%place% 

Return


You could just get firefox, and there is a google/yahoo/ebay search box built in. (though you have to get a simple add-on for wikipedia)

Marco Kotrotsos
  • Guests
  • Last active:
  • Joined: --
Yeah I know, but moving my hands to the mouse just doesn't cut it anymore. :)

I'm gonna dive into hotstrings some more , thanks alot for the code!!
Marco

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
wo said anything about using a mouse? :D

In firefox
send, !d{tab}
puts you in the search box. Ctrl Up and Ctrl Dwon cycle the search engine.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

!d{tab} puts you in the search box

So does Ctrl+K

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
indeed. I always do the brute force method...

Marco Kotrotsos
  • Guests
  • Last active:
  • Joined: --
thanks- That's great- But how about making it even more generic and execute in place. without an input box. Just there where i'm typing.

like for stuff that's not in the searchbox of firefox like say ping.

what I would like is to map hotstring arguments like (this is just an example usage)

ping:11.11.11.11
would yield me something like
11.11.11.11 is alive

or

checkmail:mondy
you have 1 new message

so to have that command execute in place.

a definition would be:

hotstringcommand:arguments


I am looking high and low but I am not finding any information about this. Is it at all possible?
Thanks very much!
Marco

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
for certain things, like "checkmail" you could maybe do it. Otherwise, there is no built-in command for this. It would be quite custom. You can write something using the Input commandf, and probably also RegexMatch

Marco Kotrotsos
  • Guests
  • Last active:
  • Joined: --
Oh no i just want to see if it would be possible to call any custom command with just a hotstring and an argument. Like any arbitrary command using a commandstructure like

command:arguments

but it could be any command that triggers any function not just those beforementioned.

that is vital to my needs, that I can type a command anywhere and that it triggers a function and passes the arguments to that function- what that function does or returns does not really matter yet. :)

Thanks, Marco

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
yes, I understand your request. There is no built in functionality for this, unless you write something custom for hotsrings using the input command.

By using input, you probably won't be able to see your arguments as you type them (you can if you process each letter right away)


;can't use wiki: due to : being used to make the hotstring
:*:wiki>::
;wait for arguments and Enter key
Input  arguments, V I , {enter}

;clear out the input
numchars := StrLen(arguments)+1
send {bs %numchars%}
sleep, 1

;do any needed argument parsing here
StringReplace, arguments, arguments, %A_space% , _, A 
sleep, 1

;do something with the arguments
run, iexplore.exe http://en.wikipedia.org/wiki/%arguments%
return

:*:goog>::
;wait for arguments and Enter key
Input  arguments, V I , {enter}

;clear out the input
numchars := StrLen(arguments)+1
send {bs %numchars%}
sleep, 1

;do any needed argument parsing here
StringReplace, arguments, arguments, %A_space% , +, A 
sleep, 1

;do something with the arguments
run, iexplore.exe http://www.google.com/search?q=%arguments%
return
   
*TESTED*

type wiki> (I now call it the wiki prompt) and the prompt will disappear. Type your argument (space is allowed) and press Enter. It will then process your request.

you can also turn the Input into a function, so you don't have alot of repeated code, which is a good idea.

also, I used > instead of : because
::wiki:::
replaces wiki with :, instead of replacing wiki: with nothing.

Marco Kotrotsos
  • Guests
  • Last active:
  • Joined: --
Hey great- thanks alot! I appreciate your help!
kind regards,
Marco

  • Guests
  • Last active:
  • Joined: --
Marco,

Very cool idea. Thank you.

Engunneer,

This script isn't working for me, though I'd really like to use it. I'm on Win XP SP2 using AHK v.1.0.48.03. I hadn't seen the :*: syntax before and it is too short a string to search on.

I'd love an explanation of the syntax, and would really like to get this script to work.

Thx,

D

dblanchard
  • Members
  • 32 posts
  • Last active: Jul 16 2014 01:43 AM
  • Joined: 14 Feb 2007

Marco,

Very cool idea. Thank you.

Engunneer,

This script isn't working for me, though I'd really like to use it. I'm on Win XP SP2 using AHK v.1.0.48.03. I hadn't seen the :*: syntax before and it is too short a string to search on.

I'd love an explanation of the syntax, and would really like to get this script to work.

Thx,

D


Sorry, that was me, not Guest. Though he/she sure posts a lot.

anelmuca
  • Members
  • 49 posts
  • Last active: Jul 10 2013 01:11 PM
  • Joined: 06 Oct 2011
Hi Engunneer, I loved your idea and how simply you did it!!! (2 years ago)

I came across this post during a research because I want to use variables as hotstrings (variables from an ini file).

Anyway, I took your code and I edited it a little to make it more intuitive for me. I post my code in case you or anyone else likes the "improvements".

; SEARCH IN GOOGLE
; Notice the "space" after google, you can still type google. (follow the word google with a dot if you don't want to trigger it or change the hotstring to "goog " for example.)

:*b0:google ::
ToolTip,`n Type something and hit a DOT or ENTER`n,0,0
SoundBeep ; a little bip to remind you that typing "Google " will search what you type after the space.
Input, search, V I L30 T10, {Enter}.{Esc}`,{tab} ; After the input you can push enter, dot, escape, comma or tab. The maximum length of input is 30 characters. You have to type the input in 10 seconds or it won't search it.
If ErrorLevel = Max
{
ToolTip
Return
}
If ErrorLevel = Timeout
{
ToolTip
Return
}
ToolTip
number := StrLen(search)+8 ; I delete the hotstring along with the input
send {bs %number%}
sleep, 1
StringReplace, search, search, %A_space% , +, A
sleep, 1
Run http://www.google.com/search?q=%search%,,max
; Run explorer, firefox or chrome (my own browser) and run it maximized
Return

; SEARCH IN GOOGLE ADDING THE WORD "WIKIPEDIA".
; I don't like to search in Wikipedia.

:*b0:wiki ::
ToolTip,`n Type something and hit a DOT or ENTER`n,0,0
SoundBeep
Input, search, V I L30 T10, {Enter}.{Esc}`,{tab}
If ErrorLevel = Max
{
ToolTip
Return
}
If ErrorLevel = Timeout
{
ToolTip
Return
}
ToolTip
number := StrLen(search)+6
send {bs %number%}
sleep, 1
StringReplace, search, search, %A_space% , +, A
sleep, 1
Run http://www.google.com/search?q=wikipedia+%search%,,max
Return

; SEARCH IN YOUTUBE.

:*b0:youtube ::
ToolTip,`n Type something and hit a DOT or ENTER`n,0,0
Soundbeep
Input, search, V I L30 T10, {Enter}.{Esc}`,{tab}
If ErrorLevel = Max
{
ToolTip
Return
}
If ErrorLevel = Timeout
{
ToolTip
Return
}
ToolTip
number := StrLen(search)+9
send {bs %number%}
sleep, 1
StringReplace, search, search, %A_space% , +, A
sleep, 1
Run http://www.youtube.com/results?search_query=%search%,,max
Return

; SEARCH IN PIRATE BAY (torrents)

:*b0:pb ::
; If you change the hotstring to "Pirate " remember to add some characters to the variable %Number%
SoundBeep
Input  search, V I L30 T10, {Enter}.{Esc}`,{tab}
If ErrorLevel = Max
{
ToolTip
Return
}
If ErrorLevel = Timeout
{
ToolTip
Return
}
number := StrLen(search)+3
send {bs %number%}
sleep, 1
StringReplace, search, search, %A_space% , +, A
sleep, 1
Run http://thepiratebay.org/search/%search%/0/7/0,,max
Return

; SEARCH IN SPANISH PHONE DIRECTORY.
; Only useful for spanish people. Try typing QDQ and then an spanish name like CARLOS GARCIA FERNANDEZ or LUIS MARTINEZ.

:*b0:qdq ::
ToolTip, Escribe algo y pulsa un PUNTO o INTRO,0,0
Soundbeep
Input, buscar, V I L40 T10, {Enter}.{Esc}`,{tab}
numero := StrLen(buscar)+4
If ErrorLevel = Max
{
ToolTip
Return
}
If ErrorLevel = Timeout
{
ToolTip
Return
}
ToolTip
send {bs %numero%}
sleep, 1
StringReplace, buscar, buscar, %A_space%, +, A
sleep, 1
Run http://es.qdq.com/blancas/%buscar%/loc/vizcaya/bilbao/filtro-C/calle-/num-/pag-/rows-15/,,max
Return

; SEARCH IN SPANISH DICTIONARY.
; Useful to look up the meaning or check the spelling.

:*b0:rae ::
; You can change the hotstring to "spa " for example.
; RAE means Royal Academy of the Spanish Language, it's the "official" dictionary.
Soundbeep
Input, buscar, V I L20 T10, {Enter}.{Esc}`,{tab}
numero := StrLen(buscar)+4
If ErrorLevel = Max
Return
If ErrorLevel = Timeout
Return
send {bs %numero%}
sleep, 1
; StringReplace, buscar, buscar, %A_space%, +, A
sleep, 1
Run http://buscon.rae.es/draeI/SrvltConsulta?TIPO_BUS=3&LEMA=%buscar%,,max
Return

; HOTKEY WIN + G TO SEARCH SELECTED TEXT IN GOOGLE.

#g::
Clipboard=
Send ^c
Clipwait,0
Search := Clipboard
; Actually I don't really use control + C because I use Clip() by Berban, it's much better than working with the clipboard.
; I strongly recommend to look it up.
; If you use Clip() all the above would be replaced by:
; Search := Clip()
Sleep 100
If Search= ; if there wasn`t anything selected just open Google
{
Run http://www.google.com,,max
Return
}
; If there was something selected continue
Number := StrLen(Search)
If Search > 30 ; if what was selected is a long string don't search it
Search=
If Search < 3 ; if it's too short don't search it
Search=
If search is number ; if what was selected was a number like 183902038 don't search it
Search=
If Search contains \\,:\ ; if what was selected was a file don't search it
Search=
If Search=
{
Run http://www.google.es,,max
Return
}
; Else
Run http://www.google.com/search?q=%search%,,max
Sleep 500
Search=
Return

/*

; This is the function Clip() by Berban.
; This is all you need, it's not a library or anything complicated.
; Thanks to Berban for this.
; You can use Clip() instead of Control + C in my hotkey #g.
; http://www.autohotkey.com/forum/topic75550.html

Clip(Text="", ReSelect="")
{
   Static BackUpClip, Stored, BadWindowClasses := "ATH_Note`nAutoHotkeyGUI"
   If (A_ThisLabel = "Clip")
      Return Stored := "", Clipboard := BackUpClip, BackUpClip := ""
   If (Text <> "") {
      WinGetClass, WinClass, A
      Mode := InStr("`n" BadWindowClasses "`n", "`n" WinClass "`n") ? 2 : 1
   }
   If (Mode <> 2) {
      If Stored
         SetTimer, Clip, Off
      Else If (Stored := True)
         BackUpClip := ClipboardAll
      Clipboard =
      If Mode {
         Clipboard := Text
         ClipWait, 3
         SendInput, ^v
      } Else {
         SendInput, ^c
         ClipWait, .2
      }
      SetTimer, Clip, -700
   } Else
      Loop, Parse, Text, `n, `r
      {
         If (A_Index <> 1)
            SendInput, {Enter}
         SendInput, {Raw}%A_LoopField%
      }
   If !Mode
      Return Clipboard
   Else If (ReSelect = True) or (Reselect and (StrLen(Text) < 3000)) {
      StringReplace, Text, Text, `r, , All
      StringReplace, Text, Text, `n, `n, UseErrorLevel
      SendInput, % "{Shift Down}" (ErrorLevel ? "{Up " ErrorLevel "}{End}" : "") "{Left " StrLen(SubStr(Text A_Space, 1, InStr(Text, "`n") - 1)) "}{Shift Up}"
   }
}
Clip:
If (A_ThisLabel = "Clip") {
   Clip()
   Return
}
*/

Hope it's useful for somebody, any more ideas?