AutoHotkey Community

It is currently May 27th, 2012, 10:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Universal Shortcuts
PostPosted: March 1st, 2005, 5:07 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
This started out as something small, then grew :P.

I am at work. At work I have no firefox. At work I am very bored. At work I have AHK.

I started out writing konqueror-style shortcuts for IE. Then it quickly expanded into a framework for easily making such shortcuts for a wide variety of programs with very little work.

Code:
shortcut =
replace =
control =
window =

:B0C:gg::
   shortcut = gg
   replace = http://www.google.com/search?q=$replace$
   GoSub, IEShortcut
return

:C:ahk::
   shortcut = ahk
   replace = http://www.autohotkey.com
   GoSub, IEShortcut
return

:C:docs::
   shortcut= docs
   replace = My Documents
   GoSub, ExplorerShortcut
return

IEShortcut:
window = ahk_class IEFrame
control = Edit1
GoSub, DoShortcut
return

ExplorerShortcut:
window = ahk_class ExploreWClass
control = edit1
GoSub, DoShortcut
return


DoShortcut:
   IfWinActive, %window%
   {
      ControlGetFocus, ctrl, %window%
      If ctrl = %control%
      {
         KeyWait, Enter, D ;wait for the user to type the parameters
         ControlGetText, text, %control%, %window%
         Stringlen, first, shortcut
         first += 1 ;to handle an end key
         StringLen, len, text
         StringRight, param, text, (len - first)
         param = %param%
         StringReplace, out, replace, $replace$, %param%
         temp = %clipboard%
         clipboard = %out%
         Send, ^a{del}^v{Enter}
         clipboard = %temp%
         shortcut = 
         replace =
      }
   }
return



The only really important bits of that is the DoShortcut sub. The rest of it is examples. Basically to use the framework, you make a sub that sets the variables window and control for whatever program you want it triggered for. I included such methods for IE and Explorer windows. You can make as many as you need with no fuss. Then in a hotstring you merely set the shortcut and replace variables (putting $replace$ in where you want parameters placed) and call the desired Shortcut sub. Poof. Instant shortcut.

The examples let you type something like gg: autohotkey to search google for autohotkey. Type to jump here, and in an Explorer window, type to jump to my documents. The nice thing about using hotstrings is that you can easily set the triggering options for each shortcut individually.

Give it a try and let me know if there are any horrible bugs floating about.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2005, 11:57 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
That's nice. It reminds me of the hotkey/hotstring "filtering subroutine" that was suggested a while back. It would allow a batch of hotkeys/hotstrings to become context sensitive, like yours, without having to explicitly add an IfWinActive to each hotkey or hotstring.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2005, 8:07 pm 
Offline

Joined: November 23rd, 2004, 5:54 pm
Posts: 8
Very cool, I am stealing some of your ideas here. Nice script!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2005, 8:56 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Thanks! Theft is the sincerest form of flattery :P :lol:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group