AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Universal Shortcuts

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Tue Mar 01, 2005 4:07 pm    Post subject: Universal Shortcuts Reply with quote

This started out as something small, then grew Razz.

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.
Back to top
View user's profile Send private message AIM Address
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Tue Mar 01, 2005 10:57 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Soapspoon



Joined: 23 Nov 2004
Posts: 8

PostPosted: Thu Mar 10, 2005 7:07 pm    Post subject: Reply with quote

Very cool, I am stealing some of your ideas here. Nice script!
Back to top
View user's profile Send private message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Fri Mar 11, 2005 7:56 pm    Post subject: Reply with quote

Thanks! Theft is the sincerest form of flattery Razz Laughing
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group