[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: A major(?) discovery for XyWriters



As you'll discover, the AHK help files are extremely complete and helpful.
There's also a good bit of user-support at their forum:
http://www.autohotkey.com/board/


A few other things to help:

1. Amazingly helpful information can be gained by right-clicking on the
green H in your tray, and selecting Window Spy


2. If you add the next two stanzas to an all-purpose .ahk script, it
(transparently) won't interfere with Xy's or NB's or Tame-Xy's .kbd
assignments, and you can leave the all-purpose .ahk running permanently.
When you click in the Xy window, the AHK script instantly goes into suspension.


  [Stanza 1: Place near the top of your all-purpose .ahk script, before
any hotkey assignments]:


SetTimer, WatchActiveWindow, 100 ; checks every 100 ms to see if Xy is
running. Never had a problem with this in 5+ years.


  [Stanza 2: can go anywhere in the script]:

WatchActiveWindow:
If WinActive("EDITOR.EXE") or WinActive("ahk_class ThunderMDIForm") or
WinActive("ahk_class TameConsoleClass")

{
  Suspend On
}
else if not GlobalSuspension ; this allows you to suspend/unsuspend AHK
through a keystroke, see below

{
  Suspend Off
}
 Return

Pause:: ; Make Pause button toggle the suspending of AHK
  Suspend Toggle
  GlobalSuspension:=not GlobalSuspension
  Return

Then, if you want a particular Hotkey to work for Xy, you add "Suspend
Permit" as the FIRST line after the hotkey-e.g.,


^f1::
  Suspend Permit
  Send Carl
  Return


3. On the use of braces:
  - I find that, contra the documentation, you usually cannot add the
opening brace on the same line as the item it is to cover. It's always safe
to start the open brace on a line by itself and end it on a line by itself
(as in my examples above)


  - Apparently (and I'm still experimenting with this) you don't need
braces if the intended scope is just one line. This is illustrated in my
next suggestion (4).


4. For easy reloading of an already active .ahk script, either because
you've edited it or because it seems to have stopped working:


!r:: ; I use alt-r here
 MsgBox,4,,Save changes in the active file?
  IfMsgbox Yes
  Send ^s ; save changes <== a one-line test doesn't require braces; if
you answer No to the message box, it won't save but will go on to reload

  Reload  ; Reload this AHK script
 Sleep 1000
 MsgBox Couldn't Reload this script <== for reasons unknown, won't be
triggered unless doesn't reload in under 1000ms

 Return

If you want to edit an .ahk script in Xy and use the re-load, just put
  Suspend Permit
on the line after the !r::

5. Limit hotkey assignments (and anything else) to a specific app:

#IfWinActive Notepad
^f1::Send Carl
#IfWinActive  ; ends the limitation--in effect, says: whatever window is
active


#IfWinActive Freecell
^f1::Send Something else
#IfWinActive

I have about 20 different programs specified by an #IfWinActive for them.
You can get the Window title to use from Window Spy.


6. Finally, here's some general purpose stuff, which I was advised to
use--I don't understand some of them--at the top of the .ahk file:


; Author:   Harry Binswanger 
;AutoHotkey Version: v1.1.09.03
NYC=true ; <=== I no longer use this, but I had set "NYC" as a variable for
the script to use in adjusting things for when I was using my computer in L.A.

Process, Priority,, High ; Two consecutive commas.
SetBatchLines, -1 ; this is supposed to speed it up
#MaxHotKeysPerInterval 3000
#UseHook <== I think this is very important
#InstallMouseHook ; NEW AS OF Nov. 2nd 2010
SetCapsLockState, AlwaysOff
;SetNumLockState, AlwaysOff <== you can turn the NumLock off permanently,
but I needed it on for work in InDesign, so I commented it out.

SetStoreCapsLockMode, off
SetTitleMatchMode, 2 <== governs criteria for when you've referred to a
window, as with #IfWinActive. See the help file for what "2" means

SetTitleMatchMode, slow
SetKeyDelay -1
SetTimer, WatchActiveWindow, 100 ;

One more thing: a semicolon only acts as a comment-initiator if it is
preceded by a space or a tab. So be careful not to do, e.g.,

  Send Carl; intended comment here
when you meant:
  Send Carl ; intended comment here

Happy scripting,
Harry