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 

Some of my early creations

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



Joined: 06 Aug 2004
Posts: 10

PostPosted: Sat Aug 07, 2004 8:36 am    Post subject: Some of my early creations Reply with quote

Just discovered this program earlier this week, and so I figured I'd post some of what I've came up with to contribute to the community. If these are redundant, I apoligize, but I didn't find similar code when I searched the forums which researching towards the development of the scripts.

My goal when setting out was to create a series of autocomplete and triggerable events which would act globally, across all applications, in a universal way. This will allow me to easily switch between editors and always have the same key-triggers and styles. Additionally, it lets me now use the same keyboard shortcuts & autcompletes ("", [], {}, etc.), which I would when editing code, when I'm entering code anywhere.

This also makes it easy to keep a similar environmen t between my work PC, and my home PC. By simply keeping AHK's .ini file synced between home & the offive, my development shortcuts and tools that I've written, and use daily, are now all in sync wherever I'm working.

The code I'm going to post below is early in development, and quite realistically my first scripts. But they're working great for me, so hopefully they will for you too. Much of the code is oritented towards web development, and more will be added soon. If there's enough interest, I'll post updates down the road, as these will be quickly growing for me. AHK is exactly the kind of program I've been looking for, so I've got lots of code to write in order to eliminate many of the tasks which I'd previously cobbled together with Automate 5 (A nice program in itself, but not especially suited for a lot of what I want to do).

One more note: When I write script, I tend to outline branches and sections as clearly as possible so that future work and revisions or whatever is easy. Although the web display might be off to due to fonts or CSS or something, it really does help me when viewing it in a text editor (notepad, homesite, ultraedit, whatever). The following should help to explain the code in case it's not clear enough -It works for me at least...

Double lines (equal signs, '====') are used for the very first and last lines of a section.

Single lines (dashed, '-----') seperate a scripts header/information from its code.

Lines of tildes ('~~~~') are used for the beginning and ending lines of a script.

All scripts should have their shortcut key listed in the header section, if they have one.

Where appropriate, I've made it so that the HTML shortcuts don't work when the active Window has the word "Microsoft" in the title. This should help to keep my code editing shortcuts from interfering with those of Office, Outlook, Excel, etc.. In such cases, they'll simply pass the keystroke/trigger through to the app. Other apps can also be filtered in this way. For example, some of the HTML-oriented scripts pass through the event rather than firing when Homesite's the active window, and I'd prefer to use Homesites built in functonality over that of my scripts.

Similarly, it'll also make it so that the scripts won't work with IE. I could write a workaround for that, but I don't use IE, so it's not a concern for me.

Let me know if you find these interesting,, and/or if you'd like the updates as they're added. Also, any comments or critique is appreciated. As I said... My 1st scripts, so I'm open to ways to optimize code. Very Happy
Code:

;================================================================================
; My Auto-Complete Additions:            
; ---------------------------------------------------------------------------------
   
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Auto-Close Double Quotes:
; ---------------------------------------------------
   $+'::
   SetTitleMatchMode, 2
      IfWinActive, Macromedia HomeSite
      {
         ; If here, use Homesites internal functions by sending hotkey combo:
         Send, +'
      }
      else
      {
         Send, +'+'{LEFT}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Auto-Close Parantheses:
; ---------------------------------------------------
   $+9::
   SetTitleMatchMode, 2
      IfWinActive, Macromedia HomeSite
      {
         ; If here, use Homesites internal functions by sending hotkey combo:
         Send, +9
      }
      else
      {
         Send, +9+0{LEFT}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Auto-Close Curly Braces:
; ---------------------------------------------------
   $+[::
   SetTitleMatchMode, 2
      IfWinActive, Macromedia HomeSite
      {
         ; If here, use Homesites internal functions by sending hotkey combo:
         Send, +[
      }
      else
      {
         Send, +[+]{LEFT}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Auto-Close Brackets:
; ---------------------------------------------------
   $[::Send, []{LEFT}
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; =================================================================================



; =================================================================================
; My HTML-Related Additions:            
; ---------------------------------------------------------------------------------

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Single <br />:   (CTRL-ENTER)
; ---------------------------------------------------
   SetTitleMatchMode, 2
   IfWinNotActive, Microsoft
   {
      ^ENTER::Send, <br />
   }
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Double <br /><br />:   (SHIFT-CTRL-ENTER)
; ---------------------------------------------------
   SetTitleMatchMode, 2
   IfWinNotActive, Microsoft
   {
      +^ENTER::Send, <br /><br />
   }
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; HTML Comment:      (CTRL-ALT-SPACE)
; ---------------------------------------------------
   $^!SPACE::
      SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^!{SPACE}
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            Send, <{!}--
         }
         else
         {
            Send, <{!}--{SPACE 2}-->{LEFT 4}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Ordered List:      (CTRL-SHIFT-O)
; ---------------------------------------------------
   $^+O::
   SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^+O
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            Send, <ol>
         }
         else
         {
            Send, <ol></ol>{LEFT 5}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; UN-Ordered List:   (CTRL-SHIFT-U)
; ---------------------------------------------------
   $^+U::
   SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^+U
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            Send, <ul>
         }
         else
         {
            Send, <ul></ul>{LEFT 5}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; List Item   :      (CTRL-L)
; ---------------------------------------------------
   $^L::
   SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^L
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            Send, <li>
         }
         else
         {
            Send, <li></li>{LEFT 5}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; HTML Make Bold (Strong):   (CTRL-B)
; ---------------------------------------------------
   $^b::
      SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^b
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            ; If here, use Homesites internal functions by sending hotkey combo:
            Send, ^b
         }
         else
         {
            Send, <strong></strong>{LEFT 9}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; HTML Underline:      (CTRL-U)
; ---------------------------------------------------
   $^U::
      SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^u
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            ; If here, use Homesites internal functions by sending hotkey combo:
            Send, ^u
         }
         else
         {
            Send, <u></u>{LEFT 4}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; HTML Italicize/Emphasize:      (CTRL-i)
; ---------------------------------------------------
   $^i::
      SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^i
      }
      else
      {
         IfWinActive, Macromedia HomeSite
         {
            ; If here, use Homesites internal functions by sending hotkey combo:
            Send, ^i
         }
         else
         {
            Send, <i></i>{LEFT 4}
         }
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Insert external JavaScript:   (CTRL-ALT-J)
; ---------------------------------------------------
   $^!J::
      SetTitleMatchMode, 2
      IfWinActive, Macromedia HomeSite
      {
         ; If here, use Homesites internal functions by sending hotkey combo:
         Send, ^!j
      }
      else
      {
         Send, <script language="JavaScript" src="xxx.js" type="text/javascript"></script>{LEFT 9}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Insert In-Line Javascript:      (CTRL-SHIFT-J)
; ---------------------------------------------------
   $^+J::
      SetTitleMatchMode, 2
      IfWinActive, Macromedia HomeSite
      {
         ; If here, use Homesites internal functions by sending hotkey combo:
         Send, ^+j
      }
      else
      {
         Send, <script language="JavaScript" type="text/javascript">{ENTER}<{!}--{ENTER 2}-->{ENTER}</script>{UP 2}{TAB}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; =================================================================================



; =================================================================================
; My Javascript Additions:            
; ---------------------------------------------------------------------------------

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Line Comment:      (CTRL-SPACE)
; ---------------------------------------------------
   $^SPACE::
   SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^{SPACE}
      }
      else
      {
         Send, //{SPACE}
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Block Comment:   (CTRL-SHIFT-SPACE)
; ---------------------------------------------------
   ^+SPACE::
   SetTitleMatchMode, 2
      IfWinActive, Microsoft
      {
         Send, ^+{SPACE}
      }
      else
      {
         clipboard =
         Send, ^c/* ^v */
      }
   return
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; =================================================================================
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Aug 07, 2004 10:01 am    Post subject: Reply with quote

Looks good. A few minor points: I edited your post to use a "code" section so that its indentation (tabbing) is preserved. This makes it display nicer and also allows someone to copy & paste the script without losing its indentation. Although some of your lines now wrap to a new line due to being too long, they too will be copied and pasted correctly.

I notice at least a couple places where you have a hotkey label conditionally defined. This will not work because labels are processed at the time the script is loaded, not while it is being run. In other words, you can't conditionally define a hotkey at runtime (except by using the Hotkey command):
Quote:
SetTitleMatchMode, 2
IfWinNotActive, Microsoft
{
^ENTER::Send, <br />
}

(this is probably just an oversight since you've done it correctly in all the other hotkeys)

Finally, braces are not required around blocks that consist of only one line. Here is a revised version of a small section of your script:
Code:
IfWinActive, Macromedia HomeSite
     ; If here, use Homesites internal functions by sending hotkey combo:
     Send, +[
else
     Send, +[+]{LEFT}

You might already know this and just use them as part of your scripting style.

Although you just started with AHK, it's obvious you've spent a lot of time reading the help file and/or the forum.
Back to top
View user's profile Send private message Send e-mail
Beastmaster



Joined: 15 Apr 2004
Posts: 182

PostPosted: Sat Aug 07, 2004 12:02 pm    Post subject: Reply with quote

Quote:
When I write script, I tend to outline branches and sections as clearly as possible so that future work and revisions or whatever is easy

Nice to know that I'm not the only one with that behaviour (while a bunch of "real" developers in my area are to "smart" to waste time on that Rolling Eyes. But don't ask them about a code section after they had a 3 week holiday, unless you want to look into a real weird face ... Laughing )

Quote:
Let me know if you find these interesting,, and/or if you'd like the updates as they're added. Also, any comments or critique is appreciated.


Holy moly. Yes, indeed. Well, not every code is of use for everybody, at any time. But the worst code is the hidden one, as nobody can learn from it. Thx for yours. Very Happy
Back to top
View user's profile Send private message
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